How to properly pass an array of values to the `attr_accessible` method?
-
05-06-2021 - |
题
I am using Ruby on Rails v3.2.2 and I would like to handle an array of symbols so to pass its values to the attr_accessible
method as well as it should be made. That is, I have:
attr_array = [:one, :two, ...]
If I use:
attr_accessible attr_array
I get the following:
self.accessible_attributes.inspect
# => #<ActiveModel::MassAssignmentSecurity::WhiteList: {"[:one, :two, ..."]}>
However, I would like to get:
# => #<ActiveModel::MassAssignmentSecurity::WhiteList: {"one", "two", "..."}>
as well as it should be made.
How can I make that?
解决方案
Just like this :
attr_accessible *array
不隶属于 StackOverflow