diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-01 19:16:58 -0200 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-02-02 14:52:15 -0200 |
commit | f506c8063b3084f54aa8bd157d94f10b7aed2bf0 (patch) | |
tree | 199ca69d058f111e402ee57821e47cd4030ab8d0 /railties/guides/source/action_view_overview.textile | |
parent | 9035324367526af0300477a58b6d3efc15d1a5a8 (diff) | |
download | rails-f506c8063b3084f54aa8bd157d94f10b7aed2bf0.tar.gz rails-f506c8063b3084f54aa8bd157d94f10b7aed2bf0.tar.bz2 rails-f506c8063b3084f54aa8bd157d94f10b7aed2bf0.zip |
Add changelog, docs and guides entries
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'railties/guides/source/action_view_overview.textile')
-rw-r--r-- | railties/guides/source/action_view_overview.textile | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile index e2b69fa0d5..bc03dd7ff3 100644 --- a/railties/guides/source/action_view_overview.textile +++ b/railties/guides/source/action_view_overview.textile @@ -1124,6 +1124,79 @@ If <tt>@post.author_id</tt> is 1, this would return: </select> </html> +h5. collection_radio_buttons + +Returns +radio_button+ tags for the collection of existing return values of +method+ for +object+'s class. + +Example object structure for use with this method: + +<ruby> +class Post < ActiveRecord::Base + belongs_to :author +end + +class Author < ActiveRecord::Base + has_many :posts + def name_with_initial + "#{first_name.first}. #{last_name}" + end +end +</ruby> + +Sample usage (selecting the associated Author for an instance of Post, +@post+): + +<ruby> +collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) +</ruby> + +If <tt>@post.author_id</tt> is 1, this would return: + +<html> +<input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" /> +<label class="collection_radio_buttons" for="post_author_id_1">D. Heinemeier Hansson</label> +<input id="post_author_id_2" name="post[author_id]" type="radio" value="2" /> +<label class="collection_radio_buttons" for="post_author_id_2">D. Thomas</label> +<input id="post_author_id_3" name="post[author_id]" type="radio" value="3" /> +<label class="collection_radio_buttons" for="post_author_id_3">M. Clark</label> +</html> + +h5. collection_check_boxes + +Returns +check_box+ tags for the collection of existing return values of +method+ for +object+'s class. + +Example object structure for use with this method: + +<ruby> +class Post < ActiveRecord::Base + has_and_belongs_to_many :author +end + +class Author < ActiveRecord::Base + has_and_belongs_to_many :posts + def name_with_initial + "#{first_name.first}. #{last_name}" + end +end +</ruby> + +Sample usage (selecting the associated Authors for an instance of Post, +@post+): + +<ruby> +collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) +</ruby> + +If <tt>@post.author_ids</tt> is [1], this would return: + +<html> +<input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" /> +<label class="collection_check_boxes" for="post_author_ids_1">D. Heinemeier Hansson</label> +<input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" /> +<label class="collection_check_boxes" for="post_author_ids_2">D. Thomas</label> +<input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" /> +<label class="collection_check_boxes" for="post_author_ids_3">M. Clark</label> +<input name="post[author_ids][]" type="hidden" value="" /> +</html> + h5. country_options_for_select Returns a string of option tags for pretty much any country in the world. |