bborn/communityengine — Issue #31: Rails 3: Seeding Roles
Author: harmsk
Created: 2011-11-19 14:17:22+00:00
State: open

I'm working with a new production site, with an empty database.

I'm having difficulty seeding the default values for the Roles enumeration.

I first tried added the following lines to db/seeds.rb
Role.create!(:id => 1, :name => 'admin') I also tried Role.create!(:name => 'admin')
these result in an error... so I checked the acts_as_enumeration documentation

According to the acts_as_enumeration documentation I should be able to do this:
class Role < ActiveRecord::Base
require_from_ce 'models/role'

create :id => 1, :name => 'admin'
create :id => 2, :name => 'moderator'
create :id => 3, :name => 'member'
end

However, this doesn't work either. I've worked around this for now using rake db:fixtures:load FIXTURES=roles

But, is there a better way to seed these values?

FYI... you might want to look into simple_enum for this... I've used it in several places and I'm rather happy... If you'd like to switch to this I'd be happy to help.