13
我试图通过JSON注册有一项用户,但不断收到ActiveModel::ForbiddenAttributesError
轨道4和设计 - 通过JSON API用户注册
class Api::V1::RegistrationsController < ApplicationController
skip_before_filter :verify_authenticity_token
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json => user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
warden.custom_failure!
render :json => user.errors, :status=>422
end
end
def user_params
params.require(:user).permit(:email, :password)
end
end
这里是我的JSON请求:
Processing by Api::V1::RegistrationsController#create as JSON
Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}}
我知道这与强参数有关,但尚未能破解它。