Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
# # Takes a lookup table with an id/label, and will make the id available via a symbol-ized label. # # tableobject: The table object name (e.g. table name is 'account_statuses'; table object is AccountStatus) # # Usage: # @statuses = lookup_table AccountStatus # # If: # :id => 1, :label => 'Registered' # :id => 2, :label => 'Recurring' # :id => 3, :label => 'Closed' # # Then: # @statuses[:registered] => 1 # @statuses[:recurring] => 2 # @statuses[:closed] => 3 # def lookup_table(tableobject) collection = {} tableobject.all.each do | entry | collection.merge!({ # Convert the string to be more symbol-like entry.label.underscore.split(' ').join('').camelize.downcase.intern => entry.id }) end return collection end
This paste will be private.
From the Design Piracy series on my blog: