Hello, On every page of my app I want to show a user's projects... So which controller do I use to make sure that @projects from the projects controller is being made available in the view?
Thanks
Hello, On every page of my app I want to show a user's projects... So which controller do I use to make sure that @projects from the projects controller is being made available in the view?
Thanks
In your application_controller do the following:
before_filter :load_projects
def load_projects
@projects = Project.all
end
That will run the load_projects method on every request and populate the @projects variable.
You can also add conditions to your before filter like so:
before_filter :load_projects, :only => [:index]
def load_projects
@projects = Project.all
end
See more about ActionController filters: