2012-12-29 2 views
0

사용자가 Devise를 통해 스캐 폴딩을 통해 프로필을 만들었으므로 모든 것이 잘 작동하지만 프로필에 사용자를 "연결할"수 없습니다.프로필 컨트롤러와 사용자 컨트롤러를 연결하는 방법은 무엇입니까?

이것은 내가 지금까지 한 일이다 -

user.rb

has_one :profile 

profile.rb 나도 프로파일 테이블에 마이그레이션을 통해 USER_ID 컬럼을 만든

belongs_to :user 

.

이제/profiles/new 양식을 작성하면 프로필이 작성되지만 user_id 필드가 NULL이므로 사용자와 연결되지 않습니다. 또한 사용자는 여러 개의 프로필을 만들 수 있습니다. 내가 생각하기에 그는 내가 작성한 것처럼 오직 하나만 만들 수 있습니다 : has_one relationship?

어떤 도움말이 필요합니까?

편집 - profiles_controller 파일에, 나는 또한

@user_profile = current_user.userprofile.new(params[:user_profile]) 

@user_profile = UserProfile.new(params[:user_profile]) 

을 변경하려하지만 '사용자 프로필'은

답변

2
@user_profile = current_user.userprofile.new(params[:user_profile]) 

일해야 정의되지 않은 메서드를주고있다
@user_profile = current_user.build_user_profile(params[:user_profile]) 
+2

@user_profile = current_user.build_profile (params [: user_profile])'(http://guides.rubyonrails.org/association_basics.html#has_one-association-reference 참조) – Baldrick

+0

아 맞아 맞아. . 답변이 수정되었습니다. –

+0

아직 동일한 오류가 발생했습니다 - 정의되지 않은 메소드'build_profile ' – iCyborg

관련 문제