Skip to content

Instantly share code, notes, and snippets.

@mrichman
Created May 19, 2009 20:08
Show Gist options
  • Save mrichman/114353 to your computer and use it in GitHub Desktop.
Save mrichman/114353 to your computer and use it in GitHub Desktop.
Using seed-fu with users and roles
# db/fixtures/roles.rb
%w(admin normal guest).each do |r|
Role.seed(:name) do |s|
s.name = r
end
end
# db/fixtures/users.rb
admin_role = Role.find(:first, :conditions => "name = 'admin'")
normal_role = Role.find(:first, :conditions => "name = 'normal'")
guest_role = Role.find(:first, :conditions => "name = 'guest'")
user = User.seed(:login, :email) do |s|
s.login = "admin"
s.email = "[email protected]"
s.first_name = "System"
s.last_name = "Administrator"
s.password = "admin"
s.password_confirmation = "admin"
end
user.roles << admin_role
user.roles << user_role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment