轨道哈希与未知的键和强大的参数 [英] Rails hashes with unknown keys and strong parameters
问题描述
我有一个Rails应用程序,它在一个名为 properties
的字段中存储了一个序列化的散列。
虽然是未知的,所以我不知道有一个方法来允许这与强参数。
当谷歌搜索,我发现这一点: https://github.com/rails/rails/issues/9454 ,但我无法弄清楚究竟是什么解决方案基本上,我的问题是:如何配置强参数以允许使用未知键的哈希?
感谢您的帮助!
您的需求与强参数目标完全相反 ,当我们定义强参数时,基本上我们会列入即将到来的参数。
在你的情况下,我们完全不知道按键,所以不需要在那里进行强大的参数检查。这将解决您的问题。
I have a rails application that stores a serialized hash in a field called properties
.
The hashes keys are unknown though, so I don't know of a way to allow this with strong parameters.
When googling, I found this: https://github.com/rails/rails/issues/9454, but I couldn't figure out exactly what a solution would be.
So basically, my question is: How can you configure strong parameters to allow hashes with unknown keys?
Thanks for all help!
Your need is completely opposite of objective of strong parameter, when we define strong parameter then basically we are going to whitelist the coming params.
and here in your case we exactly don't know the keys, so there is no need to put strong parameter check over there. that will solve your problem.
这篇关于轨道哈希与未知的键和强大的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!