Ruby on rails 3 Rails 3-警告:Can';t大规模分配受保护的属性:用户\u ID
我在课程和用户之间有着千丝万缕的联系Ruby on rails 3 Rails 3-警告:Can';t大规模分配受保护的属性:用户\u ID,ruby-on-rails-3,has-many-through,Ruby On Rails 3,Has Many Through,我在课程和用户之间有着千丝万缕的联系 class Course < ActiveRecord::Base belongs_to :user has_many :enrollments, :dependent => :delete_all has_many :users, :through => :enrollments attr_accessible :description, :duration, :name, :prerequisites, :short
class Course < ActiveRecord::Base
belongs_to :user
has_many :enrollments, :dependent => :delete_all
has_many :users, :through => :enrollments
attr_accessible :description, :duration, :name, :prerequisites, :short_name, :start_date, :user_id
accepts_nested_attributes_for :users, :allow_destroy => true
attr_accessible :users_attributes
以@c为课程
任何帮助都将不胜感激,
谢谢。这是
用户id
,而不是用户id
你需要将
用户ID
添加到你的attr\u accessible
哦,天哪,我真不敢相信我是多么瞎!非常感谢。
class User < ActiveRecord::Base
has_many :subjects, :class_name => "Course" # to get this call user.subjects
has_many :enrollments, :dependent => :delete_all
has_many :courses, :through => :enrollments
class Enrollment < ActiveRecord::Base
belongs_to :course
belongs_to :user
attr_accessible :course_id, :user_id
end
@c.update_attributes({:user_ids => [7,8]})