Topic: Seeds File Cleanup Suggestions

Hi All,

Coming from a Java background and I'm still trying to get a handle on Ruby best practices.  I'm almost certain there is a cleaner way to complete this functional (yet ugly) seed code.  I'm trying to prevent a double entry in my database when I seed more than once. Any suggestions welcome!

# Create Roles

  ENGINEER = "Engineer"
  ADMIN = "Admin"
  
  begin
    @admin = Role.where("name = ?", ADMIN)
  rescue
    @admin = Role.create(:name => ADMIN)
  end
  
  begin
    @engineer = Role.where("name = ?", ENGINEER)
  rescue
    @engineer = Role.create(:name => ENGINEER)
  end

# Create Testing Users
  @admin_user = User.new(:email => "a@a.com", :password => 'asdfasdf')
  @engineer_user = User.new(:email => "b@b.com", :password => 'asdfasdf')
  
# Add Roles to users
  @admin_user.role = @admin
  @engineer_user.role = @engineer
  
# Save the users with their role assignments
  @admin_user.save
  @engineer_user.save