Rails: Dropdown with links to show pages -
i trying put drop down in navbar users can click on links different stone show pages. code have in getting nomethoderror private method `each' called nil:nilclass.
i pretty sure private method error coming because putting code in navbar in application.html.erb rather in stone model. point me in right direction should define methods navbar? or if there else should doing instead?
here have attempted far:
application.html.erb
<div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">dropdown example <span class="caret"></span></button> <ul class="dropdown-menu"> <% @stones.each |stone| %> <li> <%= link_to stone_url %> <%= stone.name %> <% end %> </li> <% end %> </ul> </div>
application_controller.rb
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want use :null_session instead. protect_from_forgery with: :exception helper_method :current_order def each @product = product.all end def current_order if !session[:order_id].nil? order.find(session[:order_id]) else order.new end end end
you calling .each
on var @stones
, not on controller, views cant call methods controllers, unless helper methods. try use before_filter in controller set @stones
, remove each
method controller
Comments
Post a Comment