title: Rails' before_filter equivalent in Phoenix
body: <p>I've just started working on my first Phoenix app, and the issue is that I have some common lines of code in every action in my controller, that I would like to separate out. They fetch data from multiple Ecto Models and save them to variables for use.</p>
  
  <p>In Rails, I could simply define a method and call it using <code>before_filter</code> in my controller. I could access the result from an <code>@variable</code>. I understand that using <code>Plugs</code> is the key but I'm unclear on how to achieve this, more specifically:</p>
  
  <ul>
  <li>Accessing the request <code>params</code> from a <code>Plug</code></li>
  <li>and making the variables accessible in actions</li>
  </ul>
  
  <hr>
  
  <p>As a reference, this is the rails version of what i'm trying to do:</p>
  
  <pre class="lang-rb prettyprint-override"><code>class ClassController &lt; ApplicationController
      before_filter :load_my_models
  
      def action_one
          # Do something with @class, @students, @subject and @topics
      end
  
      def action_two
          # Do something with @class, @students, @subject and @topics
      end
  
      def action_three
          # Do something with @class, @students, @subject and @topics
      end
  
      def load_my_models
          @class    = Class.find    params[:class_id]
          @subject  = Subject.find  params[:subject_id]
  
          @students = @class.students
          @topics   = @subject.topics
      end
  end
  </code></pre>
  
  <p>Thanks!</p>