Rails 4 i Devise-rejestracja użytkownika przez JSON API

Próbuję zarejestrować użytkownika devise przez JSON, ale wciąż otrzymuję 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

Oto moja prośba o JSON:

 Processing by Api::V1::RegistrationsController#create as JSON
 Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "registration"=>{"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}}
Zdaję sobie sprawę, że ma to coś wspólnego z silnymi parametrami, ale nie byłem jeszcze w stanie go złamać.
Author: Jayson Lane, 2013-07-13

1 answers

Zmieniłbym:

user = User.new(params[:user])

Z:

user = User.new(user_params)

From docs:

# This will raise an ActiveModel::ForbiddenAttributes exception because it's using mass assignment
# without an explicit permit step.
def create
  Person.create(params[:person])
end
 11
Author: juanpastas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-07-13 15:45:58