Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unpermitted Parameters with Hashes in Rails

I have a hash field in my Rails model and am attempting to update it. The attribute, detail, was first generated through a migration as a text type. Afterwords, in my model, it was set as a hash through the store :detail property

class Request < ActiveRecord::Base
    store :detail
end

My strong_params are as such:

params.require(:request).permit(:name, :action, :detail => {})

However, when my Parameters go through as

Parameters: {"request"=>{"name"=>"temp", "action"=>"create", "detail"=>{"test"=>"fdsf"}}}

I am told that there is an Unpermitted parameter: test, despite the test parameter being part of the detail hash.

How do I fix this? Thanks!

like image 528
uccblack Avatar asked Mar 11 '23 22:03

uccblack


1 Answers

params.require(:request).permit(:name, :action, detail: [:test])

Another option (e. g. if you do not know the possible field names in advance) would be to serialize the detail to json string on client side, accept it as string and deserialize to a hash afterwards.

like image 67
Aleksei Matiushkin Avatar answered Mar 17 '23 02:03

Aleksei Matiushkin