Rails - creating @projects avaialble on all page loads

On every page of my application, I want to show custom projects ... So, which controller do I use to make sure that @projects from the project controller are available in the view?

thank

+3
source share
1 answer

In your application_controller application, do the following:

before_filter :load_projects

def load_projects
  @projects = Project.all
end

This will run the load_projects method for each request and populate the @projects variable.

You can also add conditions for your filter before the following:

before_filter :load_projects, :only => [:index]

def load_projects
  @projects = Project.all
end

More about ActionController filters:

+5

Source: https://habr.com/ru/post/1772040/


All Articles