Add Include Blank argument to Option Helpers


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. module ActionView::Helpers::FormOptionsHelper
  2.  
  3. def options_for_select_with_include_blank(container, selected = nil, include_blank = false)
  4. options = options_for_select_without_include_blank(container, selected)
  5. if include_blank
  6. options = "<option value=\"\">#{include_blank if include_blank.kind_of?(String)}</option>\n" + options
  7. end
  8. options
  9. end
  10. alias_method_chain :options_for_select, :include_blank
  11.  
  12. def options_from_collection_for_select_with_include_blank(collection, value_method, text_method, selected = nil, include_blank = false)
  13. options = options_from_collection_for_select_without_include_blank(collection, value_method, text_method, selected)
  14. if include_blank
  15. options = "<option value=\"\">#{include_blank if include_blank.kind_of?(String)}</option>\n" + options
  16. end
  17. options
  18. end
  19. alias_method_chain :options_from_collection_for_select, :include_blank
  20.  
  21. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.