avatar

19

Add "usage" code blocks to FormHelper methods, and new example 'bio' attribute in main usage doc to match

by chrisk, 28 Jul, 2007 04:55 AM
18 19  
2727       # Usage:
2828       #   class User < ActiveRecord::Base
2929       #     templated_attribute :website, :starting_value => 'http://'
30       #     templated_attribute :phone, :label => '(123) 555-1234'
30       #     templated_attribute :phone,   :label => '(123) 555-1234'
31       #     templated_attribute :bio,     :label => 'Tell us a little something about yourself.'
3132       #   end
3233       def templated_attribute(attr_name, options)
3334         unless included_modules.include?(InstanceMethods)
17 19  
1717       #
1818       # When you call <tt>#text_area</tt> for attributes which are not
1919       # templated, we defer to Rails's original <tt>#text_area</tt> without
20       # changes.
20       # enhhancement.
2121       #
2222       # Javascript support will be disabled if <tt>:templated_javascript =>
2323       # false</tt> is passed in the options hash of +text_area+.
2424       #
2525       # <b>Note:</b> The Javascript uses Prototype to add event handlers to
2626       # your form. Make sure <tt>prototype.js</tt> is included in your layout.
27       #
28       # Usage:
29       #   <% form_for @user do |form| %>
30       #     <label for="user_website">About you:</label>
31       #     <%= form.text_area :bio %>
32       #   <% end %>
2733       def text_area_with_templating(class_name, method, options={})
2834         args = [class_name, method, options]  # use params above for docs' sake
2935         if templated?(*args)
------
3945       # <tt>ActionView::Helpers::FormHelper#text_field</tt> so you can get
4046       # templated attribute behavior with <tt><input type="text"></tt> tags.
4147       # See notes for <tt>#text_area_with_templating</tt> above.
48       #
49       # Usage:
50       #   <% form_for @user do |form| %>
51       #     <label for="user_website">Website:</label>
52       #     <%= form.text_field :website %>
53       #
54       #     <label for="user_phone">Phone:</label>
55       #     <%= form.text_field :phone, :templated_javascript => false %>
56       #   <% end %>
4257       def text_field_with_templating(class_name, method, options={})
4358         args = [class_name, method, options]  # use params above for docs' sake
4459         if templated?(*args)