Guest User

Untitled

a guest
May 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. class SuperFormBuilder < ActionView::Helpers::FormBuilder
  2.  
  3. # Create an array of helpers to override with our label builder
  4. helpers = field_helpers +
  5. %w{date_select datetime_select time_select} +
  6. %w{collection_select select country_select time_zone_select} -
  7. %w{hidden_field label fields_for} # Don't decorate these
  8.  
  9. helpers.each do |name|
  10. define_method(name) do |field, *args|
  11.  
  12. # Get the hash option (EG the field involved)
  13. options = args.last.is_a?(Hash) ? args.pop : {}
  14.  
  15. # Create a label for that field
  16. label = label(field, options[:label], :class => options[:label_clas])
  17.  
  18. # Wrap label in paragraph, include the original helper EG: text-field
  19. @template.content_tag(:p, label +'<br/>' + super) #wrap with a paragraph
  20.  
  21. end
  22. end
  23.  
  24. # Override the submit button
  25. define_method("submit") do |field|
  26.  
  27. @template.content_tag(:p, "Test")
  28.  
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment