我有一个导航栏,我试图显示个人资料页面。但是,我遇到了一些问题。该配置文件是通过设计登录等创建的,因此用户无法在登录后创建该配置文件。我只希望该操作能够查看其配置文件并编辑其配置文件。我一直有这个问题,有人能快速看看吗?
当我输入rake routes
时,我最终会
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"
(我不认为这就是问题所在,但我也想分享这一部分)
答案 0 :(得分:1)
从您的代码看起来您应该与
链接= link_to 'Profile', user_path(@user.id)
您没有为@user_id