新手问题 [已解决] 关于 permit 处理数组类型的 value

heyen · October 19, 2016 · Last by nuanshuidai replied at August 09, 2017 · 2018 hits


如上图所示: 当 tag_ids 的值是一个数组的时候,permit 好像并没有作用,字符串形式就没有问题。

  • 这是什么原因造成的?
  • 求解决方法

根据#1 楼 @Stone 的方法,已解决,谢谢

params.require(:user).permit(:tag_ids => [])

https://github.com/rails/strong_parameters

The permitted scalar types are String, Symbol, NilClass, Numeric, TrueClass, FalseClass, Date, Time, DateTime, StringIO, IO, ActionDispatch::Http::UploadedFile and Rack::Test::UploadedFile.

To declare that the value in params must be an array of permitted scalar values map the key to an empty array:

params.permit(:id => [])

下次请帖代码,不要截图

如果 permit 中有多个参数,请把数组参数放在最后面

select 下拉框为什么也传不过去?

You need to Sign in before reply, if you don't have an account, please Sign up first.