Skip to content

Instantly share code, notes, and snippets.

@NickClark
Created February 21, 2011 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickClark/836501 to your computer and use it in GitHub Desktop.
Save NickClark/836501 to your computer and use it in GitHub Desktop.
Is there not a better way?
# So i want to have quick access to some standard roles in my Roles table
# The following works, but I am regenerating my table for scratch, and I run
# rake db:schema:load, then I get errors because rails loads all the code first,
# and when it gets to these class methods, it errors out since it cant find the
# roles table yet. Which is exactly what I am trying to do!! Any Ideas how I can improve this?
Class Role < ActiveRecord::Base
def self.admin
find_by_name "Administrator"
end
def self.user
find_by_name "User"
end
def self.moderator
find_by_name "Moderator"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment