Closed sdbondi closed 10 years ago
So you want a deep hash? Can you maybe write a test within Grape that reproduces this problem? Thx.
Will do sometime this week - You thinking something like: requires :data, type: DeepHash
?
I think a type: Hash
should make it a Hash without any additional work. I don't know what would break if that happens, but my first thought is that this is a bug.
My mistake!
Was using a strong param helper to access the params, the to_hash method does not 'unhashiemash' the deep arrays. (As it itself is not a Hashie::Mash)
def permitted_params
@permitted_params ||= declared(params, include_missing: false)
end
So I change it to this:
def permitted_params
@permitted_params ||= Hashie::Mash.new(declared(params, include_missing: false))
end
Feature request: Would it make sense to have a permitted_params helper built-in to Grape which uses the params definition to white-list the params hash?
Possibly. Open a PR/Issue? We can discuss it there.
I want to save a JSON structure (Postgres JSON field) from an api request from a param called
data
.requires :data, type: Hash
However when updating the
ActiveRecord
record the data array still contains Hashie::Mashes. I've tried params[:data].to_hash and params[:data].to_json."data": [#<Hashie::Mash ... > etc etc]
A normal ruby hash would be great, or raw json.
Thanks :)