Sunday, April 24, 2016

rails 5 hstore hash

Rails 5 now returns params as a class instance, no longer a hash.
due to the requirement to have random hashs key based on user input,
the only way to do this is to force this value by calling .to_unsafe_h

res = params.require(:detail).permit(:name, :year)
res[:specification] = params[: detail][:specification].to_unsafe_h

but if you do know your hash key, call this instead:
permit(:specification => { :keyname1, keyname2 }

if you have any suggestion, please comment :)

No comments: