Skip to content

Instantly share code, notes, and snippets.

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 nileshtrivedi/153934 to your computer and use it in GitHub Desktop.
Save nileshtrivedi/153934 to your computer and use it in GitHub Desktop.
Patch scaffolding_extensions gem for supporting enum fields
# The patch
# In the scaffold_field_tags method in helper.rb
when :enum
# array of select options will be passed in the options hash for this column
select_options = options[:select_options] || []
# each item in select_options is like [ option_label, option_value ]
s = {value.to_s => "selected='selected'"}
options.delete :select_options #we don't want to show this as an attribute in the generated HTML
"<select #{scaffold_options_to_html(options)}><option></option>#{select_options.collect{|o| "<option value='#{o[1]}' #{s[o[1]]}>#{o[0].to_s}</option>"}.join}</select>"
#################################
# In my models, I now do this:
#Make the field for status a dropdown instead of plain text field
@scaffold_column_types = {:status => :enum}
@scaffold_column_options_hash = { :status => {:select_options => [["ENABLED",'ENABLED'],["DISABLED",'DISABLED'],["PENDING_APPROVAL",'PENDING_APPROVAL'],["REJECTED",'REJECTED']] } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment