I have a module that defines custom attr_accessible
attribute as follow:
module MyModule
include ActiveModel::MassAssignmentSecurity
%w[var1 var2].each do |key|
attr_accessible key
end
end
class MyClass
include MyModule
end
Since attr_accessible is defined in ActiveModel::MassAssignmentSecurity
, I include it in MyModule
.
However, when I call object = MyClass.first; object.var1
I get the following error:
NoMethodError: undefined method `class_attribute'
Now, this method seems to be defined in active_support/core_ext/class.rb. However, even after
require 'active_support/core_ext/class'
I still get the same error message.
Which module I should include in order to access this method? I am using Rails 4, with protected_attributes
gem.
Update1: add include ActiveModel::MassAssignmentSecurity