2012-02-09 3 views
0

기본적으로 가입 양식이 작동하지 않습니다. 는 사용자가레일 : 사용자를 등록 할 수 없습니다.

(0.1ms) begin transaction 
User Exists (0.2ms) SELECT 1 FROM "users" WHERE LOWER("users"."email") == LOWER('[email protected]') LIMIT 1 
(0.1ms) rollback transaction 

존재한다고까지 내가 사람을 가입 할 때 나는 문제가 무엇인지 확실입니다. 여기 내 모델 코드와 컨트롤러 코드가 있습니다.

사용자 모델

class User < ActiveRecord::Base 
attr_accessible :name, :email, :password, :password_confirmation, :biography, :avatar 
has_secure_password 
before_create { generate_token(:auth_token) } 
validates :name, presence: true, length: { maximum: 20 } 
valid_email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.edu/i 
validates :email, presence: true, 
        format:  { with: valid_email_regex }, 
        uniqueness: { case_sensitive: false } 
validates :password, length: { minimum: 6}, :on => :create 
validates :password_digest, presence: { message: "Password can't be blank" } 
validates :biography, presence: true, length: { maximum: 140 } 
has_attached_file :avatar, :styles => { :small => "75x75>" } 
end 

사용자 컨트롤러

class UsersController < ApplicationController 

def new 
    @user = User.new 
end 

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

def create 
    @user = User.new(params[:user]) 
    if @user.save 
    redirect_to @user 
    else 
    redirect_to current_school 
    end 
end 

학교 모델

class School < ActiveRecord::Base 
    attr_accessible :name 
end 

학교 컨트롤러

class SchoolsController < ApplicationController 

def create 
school = School.find(params[:name]) 
if school 
    session[:school_id] = school.id 
    redirect_to school_path(school) 
end 
end 

def show 
    @school = School.find(params[:id]) 
    @user =User.new 
end 

end 
당신은 롤백을 보여주는 로그 때문에 16,

가입하기 양식

<%= form_for @user do |f| %> 
<%= f.text_field :name, :class => 'modal_signinfield', :placeholder => 'Name' %> 
</br></br> 
<%= f.text_field :email, :class => 'modal_signinfield', :placeholder => 'Email: Must be .edu' %> 
</br></br> 
<%= f.password_field :password, :class => 'modal_signinfield', :placeholder => 'Password: Must be at least 6 letters' %> 
</br></br> 
<%= f.password_field :password_confirmation, :class => 'modal_signinfield', :placeholder => 'Renter Password' %> 
<%= f.submit "Sign Up", :class => 'sign_up_button'%> 
<% end %> 

답변

3

, 뭔가 사용자 모델을 검증 콜백 또는 귀하의 경우 잘못된 것으로 가정 할 수있다.

가입 양식에 입력하지 않은 확인이 필요합니다.

validates :biography, presence: true, length: { maximum: 140 } 

이 조건을 new_record로 만드시겠습니까? 제거하십시오.

오류를 양식에 표시 할 가치가 있으므로 어떤 유효성 검사 오류가 발생했는지 확인할 수 있습니다.

+0

당신은 선생님입니다. 나는 그것을 잡지도 않았고, 정말 고마워요! :) – Kellogs

관련 문제