新手问题 如何获取 post 中的 jsonapi 参数

smartepsh · 2016年08月10日 · 最后由 smartepsh 回复于 2016年08月10日 · 1862 次阅读

假设请求参数如下: curl -d '{ "data": { "type":"music","attributes":{"name": "acmes"}}} --header "Accept: application/vnd.api+json" --header "Content-Type: application/vnd.api+json"

也可能在参数中存在一个对象集合,包含多个对象

在 controller 中如何获取其中的参数呢?有没有什么方法或 gem 可以方便的获取其中的参数或参数组?

我现在只能用params[:data][:attributes][:name]这样来直接拿参数...

params.dig(:data, :attributes, :name)

#1 楼 @novtopro 谢谢,那如果我想直接拿到参数的字符串形式呢?或者 hash 形式呢?有什么办法吗?

#1 楼 @novtopro 暂时用了 to_h 和 to_unsafe_h

需要 登录 后方可回复, 如果你还没有账号请 注册新账号