Norbert Melzer wrote in post #1119014:
> Standard HTML:
>
> <div>example </div>
>
> Content_tag:
>
> content_tag :div, "example"
> Am 18.08.2013 11:19 schrieb "Brandon Brown" <whicily1988@gmail.com>:
>
> Thanks.
>
> That's what I know.
>
> But how do I decide which to use?
The most (and i'd say only) useful aspect of content_tag is the ability
to iterate over a collection:
<%= content_tag_for(:tr, @people) do |person| %>
<td><%= person.first_name %></td>
<td><%= person.last_name %></td>
<% end %>
which produces items with a predictable id and class.
<tr id="person_123" class="person">...</tr>
<tr id="person_124" class="person">...</tr>
see doc:
http://api.rubyonrails.org/classes/ActionView/Helpers/RecordTagHelper.html#method-i-content_tag_for
But in most cases where you just need standard tags, you should plain
ol' html because it's much easier to maintain.
<h1><%= @person.name %></h1>
is better than
<%= content_tag :h1, @person.name %>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/244d33e7dcb8f1cd687c3eb08c0f9431%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment