Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## lib/labelling_form_builder.rb
- class LabellingFormBuilder < ActionView::Helpers::FormBuilder
- (field_helpers - %w(hidden_field) + %w(select)).each do |selector|
- src = <<-END_SRC
- def #{selector}(field, *args, &proc)
- "<div class='field'><label for=\\"\#{object_name}_\#{field}\\">\#{label_name(field)}</label> \#{super}</div>"
- end
- END_SRC
- class_eval src, __FILE__, __LINE__
- end
- protected
- def label_name(field)
- meth = "label_for_#{field}"
- self.object.respond_to?(meth) ? self.object.send(meth) : field.to_s.humanize
- end
- end
- ## app/views/account/signup.rhtml
- <%= error_messages_for :user %>
- <% form_for :user, @user, :builder => LabellingFormBuilder do |f| -%>
- <%= f.text_field :login %>
- <%= f.text_field :email %>
- <%= f.text_field :first_name %>
- <%= f.text_field :last_name %>
- <%= f.select :program, User.program_types %>
- <%= f.select :expected_graduation, User.expected_graduation_types %>
- <%= f.password_field :password %>
- <%= f.password_field :password_confirmation %>
- <p style="clear:both;margin-left:390px">
- <%= link_to "Go back", account_url %> -
- <%= submit_tag 'Sign up' %>
- </p>
- <% end -%>
Add Comment
Please, Sign In to add comment