Link to edit restaurant listing in Navbar

Hello! Can anyone please explain me how I can move the "Edit" restaurant link from the restaurant index page into the navbar? I want to make a dropdown in the navbar with: Edit profile, Edit listing, Sign out. I tried this by pasting in the navbar another <li> : <li><%= link_to "Edit Listing", edit_restaurant_path(@restaurant.restaurant_id) %></li> But i get an error: NoMethodError in Restaurants#edit , undefined method `restaurant_id' for #<Restaurant:0x00000108aa2cc0> I must somehow pass the :id param in the link like this: /restaurants/:id(.:format) ! ? Can somebody help ? Many thanks!

Posted over 5 years ago by Horia Basca
Posted over 5 years ago by Alex Yang

Try 'edit_restaurant_path(@restaurant)' instead. Let me know if it works!

0
Posted over 5 years ago by Horia B.

Hi!

I tried it out and I get : No route matches {:id=>nil} missing required keys: [:id]

0
Posted over 5 years ago by Alex Yang

Sorry, it should be 'edit_restaurant_path(@restaurant.id)'

0
Posted over 5 years ago by Horia B.

Hi Alex! Thanks for your feedback! Unfortunally the problem still persists..I posted the issue on stackoverflow to show you my files, here is the link: http://stackoverflow.com/questions/25440294/nomethoderror-undefined-method-id-for-nilnilclass-when-trying-to-set-link-t . Many thanks !!

0
Posted over 5 years ago by Alex Yang

I agree with the StackOverflow responses you got. The issue is that in order to use this link in the navbar for every page, you must make sure that the @restaurant variable is defined for every single page. Right now, you've only defined @restaurant for some of your restaurant_controller actions (and it likely isn't defined in any of your other controllers).

You should reconsider whether you want this link to appear on ALL pages or just some of them. If you do indeed want it on all pages, you'll need to make sure that @restaurant is defined everywhere.

0
Posted over 5 years ago by Horia B.

I think I got it in the end:
<li><%= link_to "Edit Listing", [:edit, @restaurant] %></li>

0
Posted over 5 years ago by Horia B.

my bad..somehow it doesnt work after all..!

0