I am trying to create a dynamic menu with simple navigation.
The problem is that the menu only works on the show action that should show dynamic menu items. All other pages gives the error:
undefined method `model_name' for #<Class:0x9236118>
I have read this, but have not found any solution:
https://github.com/andi/simple-navigation/wiki/Dynamic-Navigation-Items
My navigation.rb:
sub_nav.item :virk, 'Virksomheder', virk_path, :link => {:style => 'font-weight:bolder;', :class => 'submini'} do |virknavn|
virknavn.item :virksom, @virksomhed.try(:name), url_for(@virksomhed), :highlights_on => /virksomheder\/[0-9]+/
end
I only want the virknavn menu items to be highlighted on:
/virksomheder/:some virksomhed name
My virksomhed controller:
def index
@virksomheds = Virksomhed.all
render :layout => 'page'
end
# GET /webhosts/1
# GET /webhosts/1.xml
def show
@virksomhed = Virksomhed.find(params[:id])
render :layout => 'page'
end
I did manage to figure out that I just could set a if statement in the navigation.rb:
And it did the magick.