2011-03-27 8 views
0

은 내가이 링크를 가지고 :왜 라우팅 오류가 발생합니까?

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

을 그리고 내가 프로파일 컨트롤러에서 쇼를 액세스하려고하고있을 때 나에게 라우팅 오류가 있습니다. 여기

내 routes.rb입니다 :

resources :users do 
    resources :profiles 
end 

그리고 여기에 프로파일 컨트롤러에서 내 공연 방법입니다 :

before_create :build_profile 
: 나는 또한 내 사용자 모델에서이 콜백을

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

내가 뭘 잘못하고 있니?

+0

사용자가 많은 프로파일을 가지고? –

+0

아뇨, 하나만 ... –

+0

'@profile = @ user.profile.find (params [: id])'로 변경해야합니까? –

답변

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)'도 잘 동작해야한다. 어떤 실수 것, 전무에 대한 호출 ID : 라인 # 15 제기 /rubyprograms/dreamstill/app/views/layouts/application.html.erb보기 영화 # 지수 에서'RuntimeError에 : –

+0

는 지금은이 오류를 받고 있어요 be 4 - 당신이 정말로 nil의 id를 원한다면, object_id'를 사용하십시오. –

+0

어떻게이 오류를 수정합니까? –

관련 문제