【发布时间】:2014-07-31 21:28:47
【问题描述】:
我正在使用 Postman 测试我的 API,并且在调用 http://localhost:3000/users.json 以创建新用户时收到错误 param is missing or the value is empty: user。所有参数似乎都还可以。
我在我的应用程序控制器中设置了这个:
protect_from_forgery with: :null_session
我的控制器方法是基本的脚手架生成方法:
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
我做错了什么?
编辑:
这是我在 Postman 中所做的截图。
【问题讨论】:
-
您能否详细说明“致电localhost:3000/users.json” - 您能否将您发布的参数提供给我们?
-
另外,您确定可以直接向
users.json发送请求 - 肯定会是不同的路径吗? -
用我在邮递员中所做的屏幕截图更新了问题。 @RichPeck,我很确定我可以。我也有一条路径设置为注册,但是当我发布到它时直接给我一个错误。
标签: ruby-on-rails api rest activerecord postman