-
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?
- "":#q7
- "":#q8
- "":#q9
- "":#q10
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. 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.
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
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
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
).
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).