私はrailscast270を使用し、ユーザー向けの基本的なサインアップフォームを実装しました(このアプリではplayers
)。フォームは正常に機能しますが、jsonで認証しようとすると、エラーが発生します。これを修正する方法について何かアイデアはありますか?
POST
http://localhost:3000/players
ボディでリクエスト:
{
"email": "aaaa@baaab.com",
"username": "jaaaack",
"password": "abc123",
"password_confirmation": "abc123"
}
エラーを表示します:
<h2>Form is invalid</h2>
<ul>
<li>Password digest can't be blank</li>
<li>Password can't be blank</li>
</ul>
players_controller.rb
class PlayersController < ApplicationController
def new
@player = Player.new
end
def create
@player = Player.new(params[:player])
if @player.save
redirect_to root_url, :notice => "Signed up!"
else
render "new"
end
end
end
player.rb
class Player < ActiveRecord::Base
attr_accessible :username, :email, :password, :password_confirmation
has_secure_password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_presence_of :username
validates_uniqueness_of :email
validates_uniqueness_of :username
end
ルート.rb
get "sign_up" => "players#new", :as => "sign_up"
resources :players, :only => [:create]
root :to => 'home#index'