Joel Grannas
Joel Grannas

Reputation: 2016

Route exists, but getting error

I am trying this code in my application layout. its a "user navigation" bar at the top of the screen.

<%= link_to "My Profile", edit_profile_path, :class => "user_nav_button" %>

I am getting

No route matches {:action=>"edit", :controller=>"profiles"}

However, rake routes shows:

edit_profile GET /profiles/:id/edit(.:format) profiles#edit

If i directly go to /profiles/1/edit my view works, and the link_to shows..........

I think it has something to do with not getting the params properly... I am using devise/cancan/rolify and current_user.id is my param.

Upvotes: 0

Views: 205

Answers (2)

arieljuod
arieljuod

Reputation: 15838

if you don't want the id to be shown on the address bar, you should add a new route to something like /profile/edit without ids and, on the controller, get the id of the current_user

otherwise use edit_profile_path(@user) like patrickmcgraw said above

Upvotes: 1

patrickmcgraw
patrickmcgraw

Reputation: 2495

That path method call requires an instance of the object. Otherwise Rails doesn't know which user profile you want to edit and it doesn't guess.

edit_profile_path(@user) # Where @user is an instance of a User model from your controller

Upvotes: 3

Related Questions