2012-11-28 53 views
1

我配置自定義頁面,我的用戶配置文件稱爲profile.html.erb沒有路由匹配的定製路線

我有一個

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

在路線,我有:

resources :users do 
    member do 
    get :profile 
    end 
end 

我users_controller.rb

def profile 
    @user = User.find(params[:id]) 
    render 'profile' 
end 

錯誤發生在這一行:

<li><%= link_to "Profile", profile_user_path %></li> 

我耙路線

profile_user GET /users/:id/profile(.:format) users#profile 

的profile.html.erb正在工作,我可以訪問

http://localhost:3000/users/1/profile 

回答

4

由於這是一個成員的路線,你需要提供該成員。

<li><%= link_to "Profile", profile_user_path(@user) %></li>

只是做

<li><%= link_to "Profile", profile_user_path %></li>而不給用戶將是一個集合的路線。