Possible duplicate of Rails 4.1.0.beta1 upgrade gives me undefined local variable or method generated_feature_methods. Like it says there, try updating the protected_attributes
gem:
bundle update protected_attributes
题
This code for class assignment is ok until rails v4.0.5 but it make an error from rails 4.1.x
there is a api documentation so I guess that it is not deprecated.
I can not know what is the problem of this.
Loading development environment (Rails 4.1.1)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
NameError: undefined local variable or method `generated_feature_methods' for #<Class:0x0000010a262e28>
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/activerecord-4.1.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:30:in `block in accepts_nested_attributes_for'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `each'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/protected_attributes-1.0.5/lib/active_record/mass_assignment_security/nested_attributes.rb:16:in `accepts_nested_attributes_for'
from (irb):4:in `<class:Assignment>'
from (irb):1
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/me/.rvm/gems/ruby-2.1.1@xxx/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
It is ok on Rails 4.0.5
Loading development environment (Rails 4.0.5)
2.1.1 :001 > class Assignment < ActiveRecord::Base
2.1.1 :002?> belongs_to :group
2.1.1 :003?> has_one :event
2.1.1 :004?> accepts_nested_attributes_for :event
2.1.1 :005?> end
=> [:event]
解决方案
Possible duplicate of Rails 4.1.0.beta1 upgrade gives me undefined local variable or method generated_feature_methods. Like it says there, try updating the protected_attributes
gem:
bundle update protected_attributes