Created
May 19, 2009 20:08
-
-
Save mrichman/114353 to your computer and use it in GitHub Desktop.
Using seed-fu with users and roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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