设计用户显示页面控制器不工作
我正在使用 Rails 3.1.3(我相信是最新版本),在我的应用程序中,我使用 gem Devise 进行用户身份验证。为了添加用户显示(个人资料)页面,我添加了一个 Users_Controller.rb
class UsersController < ApplicationController
before_filter :authenticate_user!
def show
@userProfile = User.find(params[:id])
@user = current_user
@title = @userProfile.name
end
end
,在 routes.rb
文件中我有 resources :users
。 我还有一个简单的 app/views/users/show.html.erb
。 现在,当我手动转到 localhost:3000/users/1 时,这一切都工作得很好,但是,当我尝试链接到配置文件时 <%=link_to "My Profile", user_path(@user) % >
(这在我的 applicationcontroller.rb
中,以防万一)我得到一个 Action Controller: Exception No Route matches {:action=>"show", :controller="用户"}
但是当我抓取路线时,动作显示和控制器用户就会出现。我做错了什么!!! 请帮忙!!
I'm using rails 3.1.3 (I believe the latest version) and in my app I am using the gem Devise for user auth. In order to add a user show (profile) page, I added a Users_Controller.rb
class UsersController < ApplicationController
before_filter :authenticate_user!
def show
@userProfile = User.find(params[:id])
@user = current_user
@title = @userProfile.name
end
end
and in the routes.rb
file i have resources :users
.
I also have a simple app/views/users/show.html.erb
.
Now this all works fine and dandy when I manually go to localhost:3000/users/1 but, when I try to make a link to the profile <%=link_to "My Profile", user_path(@user) %>
(This is in my applicationcontroller.rb
incase that matters) I get an Action Controller: Exception No route matches {:action=>"show", :controller=>"users"}
BUT when i rake routes, action show and controller users show up. What am i doing wrong!!!
Please help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
然而
,在
ApplicationController
中这样做似乎有点奇怪。它可能应该在视图或布局文件中。
Instead of
do
However, doing that in
ApplicationController
seems a bit strange. It should probably be in a view or layout file.您应该将 @user 传递到呈现此链接的视图。
You should pass @user to the view where you render this link.
你可以尝试这个替代方案。
you can try this alternate.