2013-01-08 77 views
1

我在軌道教程下面的Lynda紅寶石。從軌道控制檯創建記錄錯誤

下面是代碼我要運行 「主題= Subject.new(:名稱=> 」第一個主題「,:位置=> 1:可見=>真)」

這是我的錯誤信息:

ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: name, position, visible 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.9/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.9/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.9/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activemodel-3.2.9/lib/active_model/mass_assignment_security.rb:230:in `sanitize_for_mass_assignment' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/attribute_assignment.rb:75:in `assign_attributes' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/activerecord-3.2.9/lib/active_record/base.rb:497:in `initialize' 
    from (irb):9:in `new' 
    from (irb):9 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start' 
    from /Users/lexi87/.rvm/gems/ruby-1.9.2-p320/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

這裏是我的模型subject.rb中:

class Subject < ActiveRecord::Base 
# attr_accessible :title, :body, :name, :position, :visible 
end 
+0

http://stackoverflow.com/questions/3944288/warning-cant-mass-assign-protected-attributes –

回答

3

您需要取消註釋attr_accessible,線與解釋者忽略#字符開始

class Subject < ActiveRecord::Base 
     attr_accessible :title, :body, :name, :position, :visible 
    end 

不能大規模指派保護的屬性:名稱,位置,可見

attr_accessible規定,可以通過大規模分配設置的屬性的列表。

+0

對不起,我忘了提及我之前張貼在這裏。這沒有什麼區別。我只是再次做了檢查。 –