2011-12-23 26 views
0

我正在使用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。 現在,當我手動進入本地主機:3000 /用戶/ 1,但當我嘗試鏈接到配置文件<%=link_to "My Profile", user_path(@user) %>(這是在我的applicationcontroller.rb incase重要)時,這一切工作正常和花花公子我得到一個操作控制器:異常No route matches {:action=>"show", :controller=>"users"} 但是,當我耙路線,動作表演和控制器用戶出現。我究竟做錯了什麼!!! 請幫忙!!

回答

3

而不是

<%=link_to "My Profile", user_path(@user) %> 

<%=link_to "My Profile", @user %> 

但是,這樣做,在ApplicationController似乎有點陌生。它應該可能在視圖或佈局文件中。

+2

啊我想通了。而不是@user它應該是current_user – Vasseurth

1

您應該將@user傳遞給您呈現此鏈接的視圖。

+0

我在應用程序控制器中呈現此鏈接。我應該把它傳遞給控制器​​嗎? – Vasseurth

0

你可以試試這個替代方案。

<%=link_to "My Profile", "https://stackoverflow.com/users/#{@user.id}" %> 
相關問題