Currently, I have this on the application controller…
def company_name
User.find_by_id(session[:user_id]).account.name
end
So then in each controller I have to add this, which is not very DRY.
The @company_id needs to be used in almost every page and it’s accessed
on the application.html.erb on a link @company_id = company_id (has to be added to EVERY CONTROLLER)
How can I NOT have to add the above line in every controller? Is there a
way to add it to the application controller and have it available to
application.html.erb regardless on what page im on?
Currently, I have this on the application controller…
def company_name
User.find_by_id(session[:user_id]).account.name
end
So then in each controller I have to add this, which is not very DRY.
The @company_id needs to be used in almost every page and it’s accessed
on the application.html.erb on a link @company_id = company_id (has to be added to EVERY CONTROLLER)
How can I NOT have to add the above line in every controller? Is there a
way to add it to the application controller and have it available to
application.html.erb regardless on what page im on?
How can I NOT have to add the above line in every controller? Is there a
way to add it to the application controller and have it available to
application.html.erb regardless on what page im on?
A before_filter is not restricted to use with a regular controller, it
can also be used with the application_controller.
Colin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.