Guest User

Untitled

a guest
Feb 21st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. ## lib/labelling_form_builder.rb
  2.  
  3. class LabellingFormBuilder < ActionView::Helpers::FormBuilder
  4. (field_helpers - %w(hidden_field) + %w(select)).each do |selector|
  5. src = <<-END_SRC
  6. def #{selector}(field, *args, &proc)
  7. "<div class='field'><label for=\\"\#{object_name}_\#{field}\\">\#{label_name(field)}</label> \#{super}</div>"
  8. end
  9. END_SRC
  10. class_eval src, __FILE__, __LINE__
  11. end
  12.  
  13. protected
  14. def label_name(field)
  15. meth = "label_for_#{field}"
  16. self.object.respond_to?(meth) ? self.object.send(meth) : field.to_s.humanize
  17. end
  18. end
  19.  
  20. ## app/views/account/signup.rhtml
  21.  
  22. <%= error_messages_for :user %>
  23. <% form_for :user, @user, :builder => LabellingFormBuilder do |f| -%>
  24. <%= f.text_field :login %>
  25. <%= f.text_field :email %>
  26. <%= f.text_field :first_name %>
  27. <%= f.text_field :last_name %>
  28. <%= f.select :program, User.program_types %>
  29. <%= f.select :expected_graduation, User.expected_graduation_types %>
  30. <%= f.password_field :password %>
  31. <%= f.password_field :password_confirmation %>
  32. <p style="clear:both;margin-left:390px">
  33. <%= link_to "Go back", account_url %> -
  34. <%= submit_tag 'Sign up' %>
  35. </p>
  36. <% end -%>
Add Comment
Please, Sign In to add comment