인증을 위해 Devise를 사용하고 있습니다. 사용자에게 하나의 프로필과 프로필이있는 두 개의 모델이 있습니다.devise current_user vs user_id가 params, 중첩 된 리소스로 전달되었습니다. 업데이트 동작
class User < ActiveRecord::Base
has_one :profile, dependent: :destroy
end
class Profile < ActiveRecord::Base
belongs_to :user
end
resources :users do
resource :profile
end
내가이 잘 때문에 느끼지 않는다
# e.g. users/123/profile
current_user.profile.update(profile_params)
를 다음을 수행 prifile#new
에 루트가 등
사용자 프로필을 업데이트하려면 내가 접두사 new_user_profile_path(current_user)
를 사용하여 새 사용자 프로필을 만들려면 프로필 params
에 the user_id => 123
을 사용하고 있지 않습니다. 대신 user_id로 사용자 프로필을 찾아야합니까? 예 :
@profile = Profile.find_by(user_id: params[:user_id])
@profile.update(profile_params)
또한 사용자는 다른 사용자의 프로필을 수정할 수 없습니다.
의견에 감사드립니다.
http://weblog.jamisbuck.org/2007/2/5/nesting-resources – max