Skip to content
andi edited this page Sep 13, 2010 · 49 revisions

work in progress…

Two items are selected at the same time. What am I doing wrong?


The method ‘render_navigation’ is undefined when rendering the view. How can I fix this?

If you get an error like undefined local variable or method `render_navigation' for #<ActionView::Base:0x506d080> when rendering the view, please make sure that you have added the simple-navigation gem as a gem-dependency in your environment.rb file.


Only a part of my configured navigation gets rendered, the rest is just missing. What could be the problem?

Some of the earlier 2.×.x versions ignore errors that occur in the navigation config file. In case of an error the evaluation of the file just stops silently. This has been fixed in version x.×.x, so errors are propagated correctly. Please upgrade to the newest version to fix the problem.


Can I provide the navigation items dynamically (e.g. from database) instead of using a config file?

Yes you can. However, this is currently kind of a hidden and undocumented feature that is still in its experimentation phase. If you need this, please contact me at andreas_dot_schacke_at_gmail_dot_com.


Can I add a ‘class’ or ‘id’ attribute to the generated ul-elements?

You can set the class or id of the ul-element in the config file (for any level you like):

SimpleNavigation::Configuration.run do |navigation|
  navigation.items do |primary|
    primary.dom_id = 'my_id'
    primary.dom_class = 'my_class'
    primary.item :my_primary_item, 'Home', home_path do |sub_nav|
      sub_nav.dom_id = 'my_sub_nav_id'
      sub_nav.dom_class = 'my_sub_nav_class'
      sub_nav.item ...
    end
  end
end

Can I add a ‘class’ or ‘id’ attribute to the generated li-elements?

Yes. Just add an :id or :class option to the item definition:

SimpleNavigation::Configuration.run do |navigation|
  navigation.items do |primary|
    primary.item :my_primary_item, 'Home', home_path, :class => 'my_class', :id => 'my_id'
  end
end

Can I add a custom attribute to the generated li-elements?

Yes. Like specifying an id or class for you li-elements, just add your custom attribute as an option to the item definition. It will be added to the li-element as a custom attribute:

SimpleNavigation::Configuration.run do |navigation|
  navigation.items do |primary|
    primary.item :my_primary_item, 'Home', home_path, :my_attribute => 'value'
  end
end

Can I add a ‘class’ or ‘id’ attribute to the generated a-elements (the links itself)?

There’s no way to do this. But usually you should find a solution without class or id attribute on the link itsself. You can always identify your anchor tag (for styling or javascript handling) by css-expression (using for example li#my_nav_id a).


Is it possible to place the navigation-config file in a location other than config/ ?

Yes. For example, if you would like to have your navigation config file in config/navigations/navigation.rb you can do this by adding an initializer to your app, let’s say:

config/initializers/simple_navigation.rb

where you put the line:

SimpleNavigation.config_file_path = File.join(RAILS_ROOT, 'config', 'navigations')


Can I have more than one navigation-config file for a single rails app?


If you have more than one primary navigation in your application (i.e. multiple navigation contexts), you can provide a configuration-file for each of the contexts and specify the context for which you would like to render the navigation in your view. Let’s say you have a main navigation in your app and in addition to that you have another navigation in the admin-section of your site (which possibly uses another layout). You configure your main navigation in the file config/main_navigation.rb and you have another configuration file for the admin navigation in config/admin_navigation.rb. To render the main navigation in the view you call:

render_navigation(:context => :main)

To render the admin-navigation simply call:

render_navigation(:context => :admin)

If you do not specify a context, the plugin loads and evaluates the default config file (config/navigation.rb).

Clone this wiki locally