Learning Rails
Learning Rails By Simon St. Laurent, Edd Dumbill
November 2008
Pages: 442


Welcome Guest ( Log In | Register )

Chapter 8. Wrap_field Is Not Generating The Label Names., Chapter 8 wrap_field issues
Scott Radcliff
post Jun 28 2009, 01:17 PM
Post #1


New Member
*

Group: Members
Posts: 2
Joined: 27-June 09
Member No.: 18,895



I seem to be having issues at the end of chapter 8. I have doubled checked my code and all is good. Everything works except the labels just print label to the screen instead of their names name, email, etc.

Here's my wrapping_tidy_form_builder class
CODE
class WrappingTidyFormBuilder < ActionView::Helpers::FormBuilder
  
  def country_select(method, options={}, html_options={})
    select(method, [['Canada', 'Canada'],
                     ['Mexico', 'Mexico'],
                     ['United Kingdom', 'UK'],
                     ['United States of America', 'USA']],
                  options, html_options)
  end
  
  
  def text_field(method, options={})
    wrap_field(label_for(method, options) + super(method, options), options)
  end

  def text_area(method, options={})
    wrap_field(label_for(method, options) + super(method, options), options)
  end

  def password_field(method, options={})
    wrap_field(label_for(method, options) + super(method, options), options)
  end
  
  def file_field(method, options={})
    wrap_field(label_for(method, options) + super(method, options), options)
  end

  
  def date_select(method, options = {}, html_options = {})
   wrap_field(label_for(method, options) + super(method, options, html_options), options)
  end
  
  def datetime_select(method, options = {}, html_options = {})
   wrap_field(label_for(method, options) + super(method, options, html_options), options)
  end
  
  def select(method, choices, options = {}, html_options = {})
    wrap_field(label_for(method, options) + super(method, choices, options, html_options), options)
  end

  def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
    wrap_field(label_for(method, options) + super(method, options, checked_value, unchecked_value), options)
  end
  
  private
  def label_for(method, options={})
    extra = ""
    if options[:required]
      extra = " <span class='required_mark'>*</span>"
    end
    label(:label || method) + extra + "<br />"
  end

  def wrap_field(text, options={})
    field_class = "field"
    if options[:required]
      field_class = "field required"
    end
    "<div class='#{field_class}'>" + text + "</div>"
  end
  
end


And here is the form partial
CODE
<%= error_messages_for :person %>

<% form_for(:person, @person,
        :url => { :action => ( @person.new_record? ? "create" : "update" ) },
        :builder => WrappingTidyFormBuilder) do |f| %>

  

     <%= f.text_field :name, :required => true %>


    <%= f.password_field :secret, :required => true %>


    <%= f.country_select :country, :required => true %>


    <%= f.text_field :email, :required => true %>


    <%= f.text_area :description, :rows => 10, :cols => 30 %>


    <%= f.check_box :can_send_email , :required => true%>


    <%= f.text_field :graduation_year %>


    <%= f.text_field :body_temperature %>


    <%= f.text_field :price %>


    <%= f.date_select :birthday, :required => true %>


    <%= f.datetime_select :favorite_time, :required => true %>


    <%= f.file_field :photo %>


  <p>
    <%= f.submit "Update" %>
  </p>
<% end %>


Any help is appreciated. Thanks.
-Scott
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 22nd November 2009 - 04:26 PM