-
Notifications
You must be signed in to change notification settings - Fork 0
- The method ‘render_navigation’ is undefined when rendering the view. How can I fix this?
- Only a part of my configured navigation gets rendered, the rest is just missing. What could be the problem?
- Can I provide the navigation items dynamically (e.g. from database) instead of using a config file?
- Can I add a ‘class’ or ‘id’ attribute to the generated ul-elements?
- Can I add a ‘class’ or ‘id’ attribute to the generated li-elements?
- Can I add a custom attribute to the generated li-elements?
- Can I add a ‘class’ or ‘id’ attribute to the generated a-elements (the links itself)?
- Is it possible to place the navigation-config file in a location other than config/ ?
- Two items are selected at the same time. What am I doing wrong?
- Can I have more than one navigation-config file for a single rails app?
- Can I conditionally render links to model edits only when a record is shown?
- The :if parameter doesn’t stop my link helpers from firing. The item doesn’t display, but still raises an exception. How can I fix this?
- I used the controller methods ‘navigation’ and ‘current_navigation’ to explicitly set the current navigation. What happened to them in version 3.x?
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 2.2.3, so errors are propagated correctly again. Please upgrade to the newest version to fix the problem.
Yes you can. Please refer to http://github.com/andi/simple-navigation/wiki/Dynamic-Navigation-Items for more details.
Can I add a ‘class’ or ‘id’ attribute to the generated ul-elements (when rendering the content as list)?
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 (when rendering the content as list)?
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
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
Yes, this is possible as of version 3.0.0. In the options of an item, you can add a :link key with the options for the link, e.g.
SimpleNavigation::Configuration.run do |navigation|
navigation.items do |primary|
primary.item :my_primary_item, 'Home', home_path, :class => 'li_class', :link => {:class => 'link_class', :title => 'my_title'}
end
end
The link options will be added as attributes to the generated a-tag. Using this option for the links or breadcrumbs renderer has no effect since all the options are applied to the a-tag anyways.
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')
This could have several reasons:
If you are using explicit highlighting in the controller, please make sure call current_navigation
BEFORE any render call:
class YourController < ApplicationController
def your_action
...
current_navigation :home
render :template => 'home'
end
If you’re relying on automatic highlighting based on the navigation item’s URLs, could it be that two items share the same URL?
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).
Yes. Wrap your items in conditional logic where you check if the model is nil and if the model.id is nil (new record), e.g.
if [email protected]? and [email protected]_record?
p.item :edit_model, "Edit #{@model}", edit_person_path( @model )
end
The :if parameter doesn’t stop my link helpers from firing. The item doesn’t display, but still raises an exception. How can I fix this?
That’s right. The specified item (incl. its url) still gets evaluated even if the :if param is false. If you have code in your item definitition that should only get evaluated on certain circumstances, please wrap your item in conditional logic instead to prevent link helpers from evaluating, e.g.
unless condition?
p.item :key, 'text', link
end
I used the controller methods ‘navigation’ and ‘current_navigation’ to explicitly set the current navigation. What happened to them in version 3.x?
The controller methods navigation
and current_navigation
have been removed from version 3.0 in favor of the new option :highlights_on. If you are absolutely dependent on these methods you can use them, but you have to require them explicitly:
In your rails app, add an initializer config/initializers/simple_navigation.rb
with the following content:
require 'simple_navigation/rails_controller_methods'