P
P
Pavel Zinoviev2014-04-25 23:36:46
Ruby on Rails
Pavel Zinoviev, 2014-04-25 23:36:46

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

2 answer(s)
P
Pavel Zinoviev, 2014-04-26
@zombiQWERTY

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 %>

A
Arkady Butermanov, 2014-04-26
@Arkadey

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 question

Ask a Question

731 491 924 answers to any question