title: Setting a global variable based on a value in params in Rails
body: <pre><code>Rails 5.2
  </code></pre>
  
  <p>I would like to setup a global variable, available to all controllers. This would be set, based on the value of one of the params. I tried doing this:</p>
  
  <pre><code>controllers/application_controller.rb
  
  before_action :set_book_author
  
  def set_book_author 
    @book_author = params[:book_author] if params.has_key?(:book_author)
  end
  </code></pre>
  
  <p>But since the rest call is going to /book_authors/:book_author, application_controller.rb, does not see it first.</p>
  
  <p>Is there a way to do this?</p>
  
  <h1>Example of how I understand session to be unreliable:</h1>
  
  <pre><code>class Location
    def initialize(ip)
      @location = location_request(ip)  
    end
  end
  
  class ApplicationController &lt; ActionController::Base
    before_action :set_location
  
    def set_location(user_ip)
      session[:user_location] = Location.new(user_ip)
    end
  end
  </code></pre>
  
  <p>As soon as I am no longer using Location, the app will raise an exception, if I try to use session[:user_location]</p>