0

Rails が form_for などを使用してフォーム送信を処理するソリューションを探しているわけではありません。

これは私のエラーです:

Started POST "/users" for 127.0.0.1 at 2012-11-20 17:55:31 -0600
Processing by UsersController#create as JSON
  Parameters: {"name"=>"Name", "email"=>"name@email.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}
   (0.1ms)  begin transaction
  User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" IS NULL LIMIT 1
   (0.1ms)  rollback transaction
  Rendered users/_signup_js.html.erb (0.0ms)
  Rendered users/new.html.erb within layouts/application (1.3ms)
Completed 200 OK in 147ms (Views: 15.9ms | ActiveRecord: 37.5ms)

*これは私の _signup_js パーシャルです:*

<script type="text/javascript">
$(document).ready(function(){
  $("#signup-button").click(function(){
    var name = $("#name").val(),
        email = $("#email").val(),
        password = $("#password").val(),
        password_confirmation = $("#password-confirmation").val();

    $.ajax({
        type: 'POST',
        url: '/users',
        data: {
            name: name,
            email: email,
            password: password,
            password_confirmation: password_confirmation
        },
        dataType: 'json'
    });
  });
});
</script>

これは私のユーザーコントローラーです:

class UsersController < ApplicationController
  def new
  end
  def create
    @user = User.new(params[:user])
    print @user
    if @user.save
      redirect_to @user
      puts "========="
      print @user 
      puts "========="
    else
      puts "not working"
      render 'new'
    end
  end

  def show
    @user = User.find(params[:id])
  end
  def index
    @users = User.all
  end
end

これは私のユーザーモデルです:

# == Schema Information
#
# Table name: users
#
#  id              :integer          not null, primary key
#  name            :string(255)
#  email           :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  password_digest :string(255)
#

class User < ActiveRecord::Base
  attr_accessible :email, :name, :password, :password_confirmation
  has_secure_password

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :name, presence: true, length: {maximum: 25}
  validates :email, presence: true,format: {with: VALID_EMAIL_REGEX}, uniqueness: {case_sensitive: false}
  validates :password, presence: true, length: {minimum: 6}
  validates :password_confirmation, presence: true
end

これらは config/routes.rb の私のルートです:

  resources :users

  root to: 'static_pages#home'

  match '/home',    to: 'static_pages#home'
  match '/about',   to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact'


  match '/signup', to: 'users#new'
4

1 に答える 1

1

@userレコードが無効のよう@user.errorsです。条件付きのその他の部分を確認してください。

于 2012-11-21T02:36:49.660 に答える