参数中有多个嵌套哈希值

时间:2017-03-07 00:47:33

标签: ruby-on-rails ruby-on-rails-5

我有一些嵌套的哈希。例如,我设置了一个参数。

Uncaught TypeError: Cannot read property 'isFormValid' of null

问题在于它没有许可证。

params = { id: @account.id, account: { 'raw_one_call_settings' => { 'service_areas' => { '0' => {'id' => 'QWE', 'ivrid' => ''}, '1' => {'id' => 'RTY', 'ivrid' => ''} } } } }

我明白了:

params.require(:account).permit(raw_one_call_settings: {service_areas:{}})

如何获取值?

2 个答案:

答案 0 :(得分:0)

尝试一下:

params.require(:account).permit(raw_one_call_settings: { service_areas: [:id, :ivrid] })

答案 1 :(得分:0)

试试这个

params.require(:account)
          .permit(:id, :account => [:raw_one_call_settings =>{:service_areas=> [:id, :ivrid] }])