저는 레일에 상당히 익숙하며 내 Devise 사용자 모델에 belongs_to 연관을 추가하려고합니다. 유증/등록 번호 편집에서기기 사용자 모델의 정의되지 않은 메소드
NoMethodError 정의되지 않은 방법은 '#
이 오류에 대한'department_id 내보기에서 collection_select에 발생 : 오류가 나는보기를 렌더링 할 때 얻을. 이 메소드는 belongs_to 연관에 의해 제공되지 않습니까?
사용자 모델 뒤로 보이는
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
belongs_to :department
end
편집보기
%h2
Edit #{resource_name.to_s.humanize}
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!
%p
= f.label :email
%br/
= f.text_field :email
%p
= f.label :department
%br/
= collection_select(resource_name, :department_id, Department.all, :id, :name)
%p
...
당신이 옳았습니다. 문제점은이 데이터베이스에서 이미 실행 된 후에 마이그레이션을 변경했기 때문입니다. 나는 지금 어리 석다. – tdahlke
아, 다행이야! 때때로 눈의 두 번째 쌍이 모든 차이를 만듭니다 ;-) – njorden