我有一个带有地址列的普通用户模型。但是当一个人尝试使用电子邮件和密码注册时,他会收到错误消息:邮编地址和城镇不能为空。您只需要注册电子邮件和密码即可。如何修复用户创建?
用户模型:
class User < ActiveRecord::Base
attr_accessible :zip, :state, :town, :address, :email, :password, :password_confirmation,
attr_accessor :password
validates_confirmation_of :password
validates :email, presence: true, format: { with: VALID_E_REGEX }, uniqueness: { case_sensitive: false }
validates :password, presence: true, format:{ with: VALID_P_REGEX }, if: proc{ password_salt.blank? || password_hash.blank? }
validates :zip, format: { with: VALID_ZIP_REGEX }
validates :address, length: { minimum: 5 }
validates :town, length: { minimum: 4 }
end
用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to root_url, :notice => "Signed up!"
else
render "new"
end
end
end
错误:
!! #<ActiveRecord::RecordInvalid: Validation failed: Phone number is invalid, Zip is invalid, Address is too short (minimum is 5 characters), Town is too short (minimum is 4 characters)>