I'm trying to understand the piece of Rails code below, and I'm not getting how the request object, with the header's attributes, is visible inside a method defined in a module that is required by the ApplicationController.
The relevant code:
in controllers/application_controller.rb
class ApplicationController < ActionController::Base
...
include Authenticable
...
end
in the controllers/concerns/authenticable.rb
module Authenticable
def current_user
@current_user = User.find_by( auth_token: request.headers['Authorization'])
end
in controllers/my_controller.rb
class MyController < ApplicationController
...
def some_action
user = current_user
...
end
...
end
As far as I (currently) know, a request object instance is created by Rack and passed onto a MyController object by Router. Correct?
This MyController object descends from ApplicationController and so inherits its properties; the opposite is not true: ApplicationController has no access to MyController properties. Correct?
If ApplicationController requires a module, it expands its properties by the methods in the module. So, these 'required' methods have no access to MyController properties, in the current case, the request object. Correct?
Where am I failing, so that method current_user inside module Authenticable can access request.headers['Authorization']?
Thanks