title: rails pass params or variable to multiple controller actions
body: <p>I have a dropdown that displays multiple "principals", when a user picks a principal and hits submit the form passes a principal id param to the controller action.  </p>
  
  <p>The issue is that I need that params value in multiple controllers. </p>
  
  <p>my view</p>
  
  <pre><code>  &lt;div class="row"&gt;
      &lt;div class="col-sm-12 button-wrapper"&gt;
        &lt;%= form_tag(principal_analytics_path, method: 'get', class: 'form-inline justify-content-center') do %&gt;
          &lt;%= select_tag 'prid', options_from_collection_for_select(Principal.all, :id, :name), :prompt =&gt; "Select Principal", class: "form-control wrapper-space" %&gt;
          &lt;%= submit_tag "Search", class: 'btn btn-primary wrapper-space', :name =&gt; nil %&gt;
        &lt;% end %&gt;
        &lt;%= link_to "Clear", principal_analytics_path, class: "text-danger" %&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>controller action</p>
  
  <p>once I get a selected principals "books" I then need a way of passing the @pri_books variable from one controller to another.  Or a way just to pass in the 'params[:prid]` to multiple controller actions.  I'm not sure how to go about doing this.  Maybe a function that passes the variable from one controller to another?</p>
  
  <pre><code>  # displays graphs about principals.
    def principal_analytics
  
      @months_back = 12
  
      if params[:prid].present?
        # takes a principals id as a parameter.  
        # @months_back will determine how many months are shown in the chart.
        @pri_books = Book.principal_books(params[:prid], @months_back)  
      end
  
      respond_to do |format|
        format.html 
        format.js {}
        format.json { render json: {success: true}}
      end    
    end
  </code></pre>