2017-08-26 90 views
-1

我在那里我试图表现出的个人资料页面的导航条。不过,我一直在遇到一些问题。配置文件是通过有一项登录和创建等,因此用户无法创建登录后一个。我只希望行动能看到他们的个人资料,并编辑自己的个人资料。我一直有这个问题,任何人都可以快速查看?NoMethodError未定义的方法`user_path`

当我rake routes I型风越来越

edit_user GET /users/:id/edit(.:format)  users#edit 
user  GET /users/:id(.:format)   users#show 

,因此我会在我的layouts文件希望能有:

= link_to 'Profile', users_path(@user_id) 

如果我在users_path有它,我得到一个错误,说明undefined method 'users_path'。如果我切换到user_path我得到一个no route matches

我的路线文件看起来像(这是整个文件)

Rails.application.routes.draw do 
    devise_for :users 
    get 'welcome/index' 
    root 'welcome#index' 
    resources :users, :only => [:show, :edit] 
end 

我的控制,我有:

def show 
    @user = User.find(params[:id]) 
end 

最后我的看法载在高达"users/show"(我不认为这就是问题的,但我觉得分享的那部分也一样)

回答

1

从你的代码看起来就像你应该

= link_to 'Profile', user_path(@user.id) 

被链接时,你不必为@user_id

定义什么
相关问题