我是相当陌生的rails,并试图将belongs_to关联添加到我的Devise User模型。 错误我在尝试渲染视图时:在设计用户模型中未定义的方法
NoMethodError在设计/注册#编辑 未定义的方法`部门标识”为#
这个错误在我看来,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 2011-01-21 20:11:44