This is the code of 'shared/subnav' partial. When i click on a link it shows error No route matches {:action=>"show", :controller=>"location"}
but routes are defined. i think there is some problem in below code.
-if current_page? location_path
= link_to 'Edit Location', edit_location_path
-if current_page? user_path
= link_to 'Edit User', edit_user_path
-if current_page? alert_path
= link_to 'Edit Alert', edit_alert_path
Here are my routes
location GET /locations/:id(.:format) locations#show
user GET /users/:id(.:format) users#show
alert GET /alerts/:id(.:format) alerts#show
As per your routes, you don't have routes for
edit
actions of location, user and alert. You have routes forshow
actions, so add routes foredit
for all the three entities and then you need to pass an object which you want to edit:current_location
,current_user
,current_alert
are the objects that you want to edit.Routes
The bottom line is that since you're defining your routes as member routes, you need to ensure you are passing the appropriate id to each of them:
This means you have to pass an
:id
value to any of these routes -- which can be done as follows:--
Error
The error is clearly being created here:
As mentioned above, you need to pass a valid "id" to the path, allowing it to pull the required object. You'll need to do the following:
More pressing, though, are your individual calls to these methods. Surely there must be a better way to manage how this logic is defined. I would try the following:
--
Helper
I think I'd make a helper like this:
This should allow you to call:
Your route helpers are defined, but are expecting an argument. For instance,
edit_user_path
is expecting to be passed auser
object, so it knows which user you want to edit.For users, you may be able to get away with something like
edit_user_path current_user
, but for other objects you will probably have to pass them in to your partial.Your show path also expecting some id value while comparing with current_page. have a look at below code this will solve your problem.