不管我如何格式化这个请求的原始部分,我都无法避免下面的解析错误。
我有一个带有通过规范的 create 方法的 Rails API,以说明控制器消息是正确的:
describe "POST power_up" do
let!(:client) { FactoryGirl.create :client, name: "joe", auth_token: "asdfasdfasdfasdfasdfasdf" }
it "should create and save a new Power Up" do
expect { post :create, format: :json, power_up: FactoryGirl.attributes_for(:power_up) }.to change(V1::PowerUp, :count).by(1)
end
end
我正在使用 Postman 尝试向其发送邮件。无论我尝试什么,我都会收到错误消息:
Started POST "/v1/power_ups.json" for 127.0.0.1 at 2014-08-30 18:05:29 -0400
Error occurred while parsing request parameters.
Contents:
{
'name': 'foo',
'description': 'bar'
}
ActionDispatch::ParamsParser::ParseError (795: unexpected token at '{
'name': 'foo',
'description': 'bar'
}
邮递员请求设置:
我也试过:
{
'power_up': {
'name': 'foo',
'description': 'bar'
}
}
来自 create 方法和强参数声明的代码power_ups_controller.rb
:
def create
@power_up = PowerUp.new(power_up_params)
if @power_up.save!
redirect_to @power_up
end
end
private
def power_up_params
params.require(:power_up).permit(:name, :description)
end