【发布时间】:2012-01-22 14:51:23
【问题描述】:
我已经通过railscast 270 为用户实现了一个基本的注册表单(在这个名为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
播放器.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'
【问题讨论】:
标签: ruby-on-rails json curl ruby-on-rails-3.1 railscasts