rails 版本 4.2.5 rake 版本 10.4.2
背景 默认管理管理账户 和 anonymous 创建 情况:几天前运行 rake:migrate 创建 admin 和 anonymous 用户成功 现在创建 admin 和 anonymous 用户不成功,注释掉(相关)验证项,创建成功
问题:求教,大家对默认数据 ,需要跳过验证,,有什么好的想法
db/migrate/001_create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :first_name
t.string :last_name
t.string :login
t.string :email
t.string :password_digest
t.boolean :admin
t.integer :status
t.string :type
t.timestamps null: false
end
user = User.new :first_name => 'User' ,
:last_name => 'administrator' ,
:email => '[email protected]' ,
:login => 'admin' ,
:password => '123456' ,
:password_confirmation => '123456' ,
:status => 1 ,
:admin => true
user.save
anonymous_user = AnonymousUser.new :first_name => 'User' ,
:last_name => 'anonymous' ,
:login => 'anonymous' ,
:email => '[email protected]' ,
:password => '123456' ,
:password_confirmation => '123456' ,
:status => 0
anonymous_user.save
end
end
app/models/user.rb
class User < ActiveRecord::Base
.
.
validates :login , exclusion: { in: %w(admin superuser anonymous) }
.
.
end