【发布时间】:2011-02-03 10:56:01
【问题描述】:
我正在使用带有 Postgresql 的 Rails 3,并且我有一个使用两个迁移定义的用户表(这里是两个 self.up 方法):
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# t.confirmable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable
t.timestamps
end
def self.up
add_column :users, :admin, :boolean, :default => false
end
现在,当我尝试使用管理员用户播种时:
User.create(:username => "admin", :email => "foobar@gmail.com",:password => "password", :password_confirmation => "password", :admin => true)
它会创建一个管理员等于 false 的用户,即使我指定了 true。我应该首先创建 User.new 并设置管理员还是一起摆脱默认设置?
【问题讨论】:
-
感谢 Zabba,原来如此简单。
标签: ruby-on-rails postgresql boolean seed