简体   繁体   English

Rails + POST请求

[英]Rails + POST Request

I am using the curb gem ( https://github.com/taf2/curb ) to create an HTTP POST request with the name value. 我正在使用遏制gem( https://github.com/taf2/curb )创建具有name值的HTTP POST请求。 My curb request looks like this: 我的路边要求看起来像这样:

http = Curl.post("http://localhost:3001/campaigns", {:name => "Facebook"})

This gets sent to a rails API but the method in the API is expecting a hash. 这被发送到Rails API,但是API中的方法需要哈希。 I then want to apply Strong Parameters (using the code below). 然后,我想应用“强参数”(使用下面的代码)。 How can I modify my POST request to send a hash called campaign with name as one attribute? 如何修改我的POST请求以发送一个名为campaign的哈希,其名称作为一个属性?

private
def campaign_params
    params.require(:campaign).permit(:name)
end

Thanks 谢谢

http = Curl.post("http://localhost:3001/campaigns", {"campaign[name]" => "Facebook"})

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

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