2013-03-14 320 views
2

所以我有一個Bootstrap導航欄頂部。路由到current_user路徑

我想LINK_TO CURRENT_USER的編輯路徑,但我總是得到錯誤:

ActionController::RoutingError at /blog 

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

這就是IM難以釋懷的時刻:

<% if current_user %> <--! user logged in? --> 
<% @user ||= current_user %> 
<%= link_to 'Settings', edit_user_path %> 
<% end %> 

我沒有這個錯誤在/用戶/ 1 /頁面,但我在其他地方都有。

也試過這一點,但並沒有幫助:

def edit 
    if params[:id] 
    @user = User.find(params[:id]) 
    else 
    @user = current_user 
    end 
end 

回答

6

試試這個,

<%= link_to 'Settings', edit_user_path(current_user) %> 
+0

工作得像魔法:)謝謝 – 2013-03-14 11:21:14

+0

如果有效,爲什麼不接受答案/ \ – 2013-03-14 11:48:06

+0

必須做的東西,但在這裏,我們去:) – 2013-03-14 12:07:24

0

edit_user_path需要用戶記錄被傳遞到路徑,請執行下列操作

<% if current_user %> <--! user logged in? --> 
    <%= link_to 'Settings', edit_user_path(current_user) %> 
<% end %>