【发布时间】:2016-06-30 20:50:41
【问题描述】:
我正在尝试在我的数据库中创建一个包含数组images 的新条目。
使用Product.new("title":"Hello World", "images":["a.jpg","b.jpg"]) 我可以毫无问题地创建一个新条目。但是当我尝试将参数传递给我的 API 时,数组仍然为空(所有其他字段都已填充)。
我使用的请求:
curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"title":"Hello World", "images":["a.jpg", "b.jpg"], "api_key":"API_KEY"}' http://localhost:3000/api/products
参数传递使用:
def product_params
params.require(:product).permit(:id, :title, :images)
end
然后使用以下命令创建一个新的数据库条目:
Product.new(product_params)
非常感谢任何帮助。
【问题讨论】:
标签: ruby-on-rails arrays ruby json parameters