我正在尝试通过 JSON 注册设计用户,但不断获得ActiveModel::ForbiddenAttributesError
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"=>"jayson@jayson.com", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"jayson@jayson.com", "password"=>"[FILTERED]"}}}
我意识到这与强参数有关,但还没有破解它。