content_tag inside content_tag

80 views
Skip to first unread message

kanna

unread,
Aug 13, 2013, 7:50:18 AM8/13/13
to rubyonra...@googlegroups.com
Hi

i tried content_tag inside content_tag bu its not working

<%= content_tag(:h1,"Arrange"+content_tag(:span,"Demo"))%>

i want like this type

<h1>Arrange <span>Demo</span></h1>

plz help.

bye

kingston.s

unread,
Aug 13, 2013, 9:11:46 AM8/13/13
to rubyonra...@googlegroups.com
call like this  content_tag(:h1,raw("Arrange"+(content_tag(:span,"Demo"))))

=> "<h1>Arrange<span>Demo</span></h1>"

kingston.s

Hassan Schroeder

unread,
Aug 13, 2013, 10:38:22 AM8/13/13
to rubyonra...@googlegroups.com
On Tue, Aug 13, 2013 at 4:50 AM, kanna <vtrk...@gmail.com> wrote:

> i tried content_tag inside content_tag bu its not working

More readably (IMO):

<%= content_tag :h1 do %>
Arrange <%= content_tag :span, 'Demo' %>
<% end %>

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

masta Blasta

unread,
Aug 13, 2013, 5:27:08 PM8/13/13
to rubyonra...@googlegroups.com
kanna wrote in post #1118570:
>More readably (IMO):
>
> <%= content_tag :h1 do %>
> Arrange <%= content_tag :span, 'Demo' %>
> <% end %>

What's wrong with just using standard HTML:

<h1>Arrange <span>Demo</span></h1>

Not sure how a bunch of nested content_tag() are 'more readable' than
that.

Personally i hate the content_tag method. It just obfuscates your DOM.

--
Posted via http://www.ruby-forum.com/.

rajesh kanna

unread,
Aug 17, 2013, 4:57:06 AM8/17/13
to rubyonra...@googlegroups.com
hi

I tried

 <%= content_tag(:h1,"Arrange".html_safe + content_tag(:span," Demo"))%>

its coming fine.

thanks for everyone .




Follow me on Twitter

Follow me on  LinkedIn

Follow me on Facebook

kanna(9742665400)
...........



--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a4281ea275f17d674b48c94267db2660%40ruby-forum.com.

Brandon Brown

unread,
Aug 18, 2013, 2:07:03 AM8/18/13
to rubyonra...@googlegroups.com
Is there any body who can explain the differences between using "standard HTML" and "content_tag"?

在 2013年8月14日星期三UTC+8上午5时27分08秒,Ruby-Forum.com User写道:

Norbert Melzer

unread,
Aug 18, 2013, 11:09:19 AM8/18/13
to Rails Mailinglist

Standard HTML:

<div>example </div>

Content_tag:

content_tag :div, "example"

--
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-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Brandon Brown

unread,
Aug 18, 2013, 10:53:15 PM8/18/13
to rubyonra...@googlegroups.com
Thanks.

That's what I know.

But how do I decide which to use?

masta Blasta

unread,
Aug 19, 2013, 10:01:45 AM8/19/13
to rubyonra...@googlegroups.com
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" <whici...@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 %>
Reply all
Reply to author
Forward
0 new messages