Skip to content

Instantly share code, notes, and snippets.

@sixty4bit
Created November 2, 2014 00:36
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 sixty4bit/8d4f6d7f45008f74cf20 to your computer and use it in GitHub Desktop.
Save sixty4bit/8d4f6d7f45008f74cf20 to your computer and use it in GitHub Desktop.
Active Record with state.
{ active: 'activate!', inactive: 'deactivate!', blocked: 'block!', suggested: 'suggest!' }.each do |state_name, trigger_name|
define_singleton_method(state_name) { where(state: state_name.to_s) }
define_method(trigger_name.to_sym) { update_attribute(state: state_name.to_s) }
end
@jhcato
Copy link

jhcato commented Nov 2, 2014

I'm going to go with sexy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment