相关疑难解决方法(0)

Rails4:如何在params中允许使用动态键的哈希?

我使用以下参数创建一个http put请求:

{"post"=> {"files"=> {"file1"=>"file_content_1","file2"=>"file_content_2"}},"id"=>"4"}

我需要在我的代码中允许哈希数组.基于手册,我尝试过这样:

> params.require(:post).permit(:files) # does not work
> params.require(:post).permit(:files => {}) # does not work, empty hash as result
> params.require(:post).permit! # works, but all params are enabled
Run Code Online (Sandbox Code Playgroud)

如何正确使用?

UPD1:file1,file2 - 是动态密钥

ruby-on-rails strong-parameters

42
推荐指数
5
解决办法
3万
查看次数

标签 统计

ruby-on-rails ×1

strong-parameters ×1