Answer the question
In order to leave comments, you need to log in
How to display menu from base on all pages using rails?
Now I have to write in each method of each controller:@items = Menu.all
Answer the question
In order to leave comments, you need to log in
Thanks everyone, I did it like this:
class ApplicationController < ActionController::Base
helper_method :menu
def menu
Menu.all
end
end
<% menu.each do |item| %>
<li>
<a href="<%= item.link %>"><%= item.name %></a>
</li>
<% end %>
https://github.com/codeplant/simple-navigation
Documentation: https://github.com/codeplant/simple-navigation/wiki
In your case something like this:
# В конфиурационном файле:
SimpleNavigation::Configuration.run do |navigation|
navigation.items do |menu|
Menu.all.each do |m|
menu.item m.name.to_sym, m.name, menu_path(m)
end
end
end
# В layout'e:
<%= render_navigation %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question