0

以下查询

$ curl http://localhost:3000/subscriptions.json -d campaign=CAMPAIGN -d phone=6446342542 -d auth_token=QWvHBzkzGCef58osasxz

正在返回

{"errors":{"phone":["can't be blank","Please enter a valid phone number."],"campaign":["can't be blank"]}}

动作是

def create
  @subscription = Subscription.create(params[:subscription])
  respond_with(@subscription)
end

该错误似乎是因为我没有params[:subscription]通过 json 发送,正如我之前的为响应与(@object)问题的模型实现特定操作所回答的那样。

如果我尝试添加Subscription.create(params[:subscription][:phone],..)我得到的细节

<h1>
 NoMethodError
   in SubscriptionsController#create

nil:NilClass 的未定义方法“[]”

4

1 回答 1

1
curl -v \
-H "Accept: application/json" \
-H "Content-type: application/json" \
-X POST \
-d '{"subscription":{"campaign":"CAMPAIGN","phone":"6446342542"}, \
"auth_token":"QWvHBzkzGCef58osasxz"}' \
http://localhost:3000/subscriptions.json

尝试类似的事情(在一行中可能更可取......没有反斜杠......我这样做是为了让您阅读清晰......但它也适用于反斜杠)

于 2012-06-06T20:16:51.567 回答