简体   繁体   English

来自Rails-API的cURL POST请求

[英]cURL POST Request from Rails-API

I'm using the rails-api gem and trying to use curl to POST some data to the API (to populate the Campaigns entity). 我正在使用rails-api gem,并尝试使用curl将一些数据发布到API(以填充Campaigns实体)。 This model only has one attribute name. 该模型只有一个属性名称。

My curl request: 我的卷曲要求:

curl -d "name=Facebook" http://localhost:3000/campaigns/

The name attribute ends up being null looking at the json response. 在json响应中,name属性最终为null。 I then changed it to this: 然后,我将其更改为:

curl -d "campaign[name]=Facebook" http://localhost:3000/campaigns/

This just seems to render some HTML in the terminal. 这似乎只是在终端中呈现了一些HTML。 Looking at the HTML there is a message on the lines of forbidden_attributes_protection . 纵观HTML有上forbidden_​​attributes_protection的线的消息。

Can anyone help? 有人可以帮忙吗?

Try adding in your 尝试添加您的

params.require(:compaign).permit(:name)

This looks like a strong parameters error. 这看起来像一个强烈的参数错误。 http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html

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

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