I've been through railscast 270 and implemented a basic sign up form for users (in this app called players
). The forms work fine, but when I try and authenticate over json, I get errors. Any ideas on how to fix this?
POST
request to http://localhost:3000/players
with body:
{
"email": "aaaa@baaab.com",
"username": "jaaaack",
"password": "abc123",
"password_confirmation": "abc123"
}
displays errors:
<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
routes.rb
get "sign_up" => "players#new", :as => "sign_up"
resources :players, :only => [:create]
root :to => 'home#index'