Chapter 8. Wrap_field Is Not Generating The Label Names., Chapter 8 wrap_field issues |
Chapter 8. Wrap_field Is Not Generating The Label Names., Chapter 8 wrap_field issues |
Jun 28 2009, 01:17 PM
Post
#1
|
|
|
|
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 |
|
|
|
![]() |
Jun 28 2009, 04:40 PM
Post
#2
|
|
|
|
This is an erratum. The (:label || method) should be either (options.delete(:label) || method), as described in the note, or just plain (options(:label) || method).
Sorry about that - it's probably the screwup that's left the most people scratching their heads. |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd November 2009 - 04:44 PM |