大家好,rails 控制台遇到了一些问题。这是错误。
>> Page.editors << me
NoMethodError: undefined method `editors' for #<Class:0x1038560e8>
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from (irb):5
这是模型之间的关系。
class Page < ActiveRecord::Base
attr_accessible :name, :permalink, :position
has_and_belongs_to_many :editors, :class_name => "AdminUser"
#has_and_belongs_to_many :AdminUser
belongs_to :subject
has_many :sections
end
第二个
class AdminUser < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :username
has_and_belongs_to_many :pages
scope :named, lambda{|first,last| where(:first_name => first,:last_name => last)}
end