Application Controller instance variable available to all views

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?

Leonel *.* wrote in post #955167:

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?

You asked a nearly identical question a few days ago. Please read
http://groups.google.com/group/rubyonrails-talk/msg/c8a1cc193e362316
again, where I answered this exact question.

Best,

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?

A before_filter is not restricted to use with a regular controller, it
can also be used with the application_controller.

Colin