73af4fece11ee3767dc13e89cdc08500

I have no idea how to create custom form builders, if anyone could look at the following view code and refactor it into a method that builds out forms / fields with the appropriate divs that would be amazing. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
- form_for :user, :url => users_path do |f|
  %ul.register
    %li
      %label{:for => 'user_login'} 
        %strong 1.
        Login
        %span.req *
      %div
        = f.text_field :login, :size => '0', :class => 'full text'
        %label.desc What you login with
    %li
      %label{:for => 'user_email'}
        %strong 2.
        Email
        %span.req *
      %div
        = f.text_field :email, :size => '0', :class => 'full text'
        %label.desc We will never sell or disclose your email to any third parties
    %li.clear
      .left
        %label{:for => 'user_password'}
          %strong 3.
          Password
          %span.req *
        = f.password_field :password, :size => '0', :class => 'full text'
        %label.desc At least 6 characters long
      .right
        %label{:for => 'user_password_confirmation'}
          %strong 4.
          Confirm Password
          %span.req *
        = f.password_field :password_confirmation, :size => '0', :class => 'full password text'
    %li
      = f.check_box :receive_updates
      %label.choice{:for => 'user_receive_updates'} Keep me updated on WB
      = f.check_box :terms_of_service
      %label.choice{:for => 'user_terms_of_service'} I agree to WB's <a href="#">Terms of Service</a>
    %li.buttons
      <button type="submit" class="button positive">
      <img src="stylesheets/blueprint/plugins/buttons/icons/tick.png" alt=""/> Register!
      </button>
      = link_to(image_tag('/stylesheets/blueprint/plugins/buttons/icons/cross.png') + "Cancel", home_url, :class => 'button negative')

Refactorings

No refactoring yet !

4d1c9dad17af98e55cb65b4efce27c42

Ben Burkert

December 11, 2007, December 11, 2007 04:56, permalink

No rating. Login to rate!

Are you asking how to build a form with haml? Or do you want to refactor the haml into erb?

73af4fece11ee3767dc13e89cdc08500

Daniel Fischer

December 11, 2007, December 11, 2007 07:40, permalink

No rating. Login to rate!

How would I build it with haml? Sorry for the confusion.

4d1c9dad17af98e55cb65b4efce27c42

Ben Burkert

December 11, 2007, December 11, 2007 23:04, permalink

No rating. Login to rate!

Haml is a templating engine that can be used instead of erb. take a look:
http://haml.hamptoncatlin.com/

73af4fece11ee3767dc13e89cdc08500

Daniel Fischer

December 12, 2007, December 12, 2007 01:54, permalink

No rating. Login to rate!

I know what HAML is, I wrote all my code in HAML as you can see.

What I want to do is reduce duplication of all my forms. So how would I refactor my above haml code into a form helper that outputs the text_field with labels like in my example?

Avatar

Dean

December 18, 2007, December 18, 2007 11:31, permalink

No rating. Login to rate!
1
2
3
script/plugin install svn://rubyforge.org/var/svn/cssformbuilder/trunk

;)
67c02d91e6570d0a0f6e67f96dd7ce28

pimp

February 27, 2008, February 27, 2008 20:09, permalink

No rating. Login to rate!

For starters, I would use %ol instead of %ul, then style the numbers with CSS

Also, in Rails 2.0 you can do f.label :name

As for the (*) action, you may need to rewrite the label helper to accept a hash {:required => true}

Your refactoring





Format Copy from initial code

or Cancel