Reputation: 1276
So i have a Bootstrap nav bar on top.
I would like to link_to current_user's edit path, but i always get the error:
ActionController::RoutingError at /blog
No route matches {:action=>"edit", :controller=>"users"}
That's what im tryin at the moment:
<% if current_user %> <--! user logged in? -->
<% @user ||= current_user %>
<%= link_to 'Settings', edit_user_path %>
<% end %>
I dont have this error at a /user/1/ page, but I have it everywhere else.
Also tried this, but didn't help:
def edit
if params[:id]
@user = User.find(params[:id])
else
@user = current_user
end
end
Upvotes: 2
Views: 2549
Reputation: 29599
edit_user_path
requires a user record to be passed to the path so do the following
<% if current_user %> <--! user logged in? -->
<%= link_to 'Settings', edit_user_path(current_user) %>
<% end %>
Upvotes: 0
Reputation: 2653
try this,
<%= link_to 'Settings', edit_user_path(current_user) %>
Upvotes: 7