ruby on rails - Accepts nested attributes safe params with jsonb and variable keys -
i attempting allow parameters go through controller data
attribute of type jsonb
, hash looks so:
data: { "en" => { "activities_text" => "activities", "playlists_text" => "playlists", "additional_playlists_text" => "additional playlists" }, "es" => { "activities_text" => "actividades", "playlists_text" => "lista de actividades", "additional_playlists_text" => "listas de actividades adicionales" } }
i got form work , i can save data 1 of language keys. issue happening because in safe params array have following:
text_customization_attributes: [:id, data: [es: [:activities_text, :playlists_text, :additional_playlists_text]]]
i need able allow through both en:
es:
, potentially other language keys
may add in future. naively thought maybe adding both line above this: text_customization_attributes: [:id, data: [en: [:activities_text, :playlists_text, :additional_playlists_text]]]
work 1 overrides other , last permitted param wins.
any thoughts on how let through both es:
, en:
?
thanks in advanced!
addendum: able save whole hash using
text_customization_attributes: [:id, data: [en: [:activities_text, :playlists_text, :additional_playlists_text], es: [:activities_text, :playlists_text, :additional_playlists_text]]]
but seems hackish.. there must better way.
as said, there may keys other en
or es
, somehow, must tell parameters permitted. in case, can map empty hash like,
text_customization_attributes: [:id, data: {}]
but, bit vulnerable opens door arbitrary input.
Comments
Post a Comment