0
基本上我的註冊表單不起作用。當我簽署某人時,表示用戶存在Rails:似乎無法註冊用戶
(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
註冊表格
<%= 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 %>
你先生真是太棒了,我甚至都沒聽清楚,非常感謝你! :) – Kellogs 2012-02-09 05:34:39