Rails 4 Unpermitted Parameters for Array

前端 未结 5 771
忘掉有多难
忘掉有多难 2020-12-07 22:07

I have an array field in my model and I\'m attempting to update it.

My strong parameter method is below

def post_params
  params[\"post\"][\"categor         


        
5条回答
  •  既然无缘
    2020-12-07 23:01

    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 => [])
    

    This is what the strong parameters documentation on Github says:

    params.require(:post).permit(:name, :email, :categories => [])
    

    I hope this works out for you.

提交回复
热议问题