2011-03-27 25 views
0

我有此鏈接:爲什麼我會收到路由錯誤?

<%= link_to "Profile", user_profile_path(current_user) %> 

,它給了我一個路由錯誤,當我試圖在配置文件控制器訪問演出。

這裏是我的routes.rb:

resources :users do 
    resources :profiles 
end 

這是我的節目在配置文件控制方法:

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

我也有這個回調在我的用戶模型:

before_create :build_profile 

我做錯了什麼?

+0

用戶有很多的配置文件? – 2011-03-27 03:33:45

+0

哦,沒有,只有一個... – 2011-03-27 03:34:38

+0

我應該將其更改爲'@profile = @ user.profile.find(PARAMS [:編號])'呢? – 2011-03-27 03:37:04

回答

1

你沒有設定檔ID。

事情是這樣的:

<%= link_to "Profile", user_profile_path(:user_id => current_user.id, :id => profile.id) %>

編輯

這是非常骯髒的,你可能不應該被嵌套在首位這些對象,但是這可能會得到你過去你目前的問題。

<%= link_to("Profile", user_profile_path(:user_id => current_user.id, :id => current_user.profile.id)) unless current_user.profile.blank? %>

你應該認真考慮在你的路由未嵌套這些,只是提供接入基於其自己的ID的配置文件,而不是用戶的ID。

resources :users 
resources :profiles 

<%= link_to("Profile", profile_path(current_user.profile)) unless current_user.profile.blank? %>

+0

'user_profile_path(CURRENT_USER,@profile)'應該工作了。 – 2011-03-27 03:38:24

+0

現在我得到這個錯誤:'RuntimeError在影片#指數 顯示/rubyprograms/dreamstill/app/views/layouts/application.html.erb其中線#15提出: 的零名爲id,這將誤在4 - 如果你真的想零的ID,使用object_id' – 2011-03-27 03:44:18

+0

如何解決這個問題? – 2011-03-27 03:54:42

相關問題