Created
July 24, 2009 09:32
-
-
Save nileshtrivedi/153934 to your computer and use it in GitHub Desktop.
Patch scaffolding_extensions gem for supporting enum fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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