私はPostgresqlでRails3を使用しており、2つの移行を使用してユーザーテーブルを定義しています(これが2つの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)
trueを指定した場合でも、adminがfalseに等しいユーザーが作成されます。最初にUser.newを作成して管理者を設定する必要がありますか、それともデフォルトをすべて削除する必要がありますか?