简体   繁体   English

Ruby on Rails将嵌套的哈希值发布到强参数

[英]Ruby on Rails posting nested a nested hash to strong params

I'm posting a hash from my ruby app, to an api built in ruby using strong params. 我正在将红宝石应用程序中的哈希值发布到使用强参数的内置红宝石的api中。

My post looks like this: 我的帖子看起来像这样:

resp = Net::HTTP.post_form(url, 'order' => @order.to_json, 'max' => '50')

The issue is, that this doesn't work with strong params 问题是,这不适用于强大的参数

[3] pry(#<Api::V1::OrdersController>)> order_params
NoMethodError: undefined method `permit' for #<String:0x007feb6890acf8>

How do I post this correctly? 如何正确发布? Also, I'd like to post a nested has under order as well. 另外,我也想发布一个嵌套的has。

params[:order][:pickup_attribute]

How can I also send that through? 我也该如何发送呢?

You are posting order as a String. 您正在order字符串形式发布order Try this: 尝试这个:

resp = Net::HTTP.post_form(url, 'order' => @order.as_json, 'max' => '50')

Notice the as_json (returns a Hash) instead of to_json (which returns a String). 注意, as_json (返回哈希)而不是to_json (返回字符串)。 If it does not work, I would like to see your controller's implementation. 如果它不起作用,我想查看您控制器的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM