Hi
I have an hstore field in my database where I store a lot of different fields.
I still want getters, setters and validations for my fields so I’ve created an array with the fields like this:
DOCUMENT_FIELDS = %w[foo bar baz]
Then I do some meta programming to create getters and setters:
DOCUMENT_FIELDS.each do |field|
define_method(field) do
…
end
define_method(“#{field}=”) do |value|
…
end
end
Now I would like to pass all fields to strong parameters to properly filter it. I tried like this:
params.require(:foo).permit(Foo::DOCUMENT_FIELDS.map(&:to_sym))
But this doesn’t work. It removes all values anyway. I guess it is because Foo::DOCUMENT_FIELDS.map(&:to_sym)
creates an array that is passed to strong parameters (and it seems to not work with arrays).
How can I get around this?
Cheers,
Linus