Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a tag using content_tag in RoR?

I have this to generate a hyperlink for me:

<%= link_to "Example", "http://example.com" %>

And I want it display in the td tag, so I want to use this content_tag to help me:

<%= content_tag(:td,"", :class => "example")%>

I want the hyperlink in my td, so I have something like this:

<%= content_tag(:td,<%= link_to "Example", "http://example.com" %>, :class => "example")%>

But I get the Syntax Error, what should I do?

like image 780
DNB5brims Avatar asked Jan 05 '10 14:01

DNB5brims


1 Answers

Inline:

<%= content_tag(:td, link_to('Example', 'http://example.com'),
                :class => 'example') %>

Or block form:

<% content_tag(:td, :class => 'example') do %>
  <%= link_to('Example', 'http://example.com') %>
<% end %>
like image 107
John Topley Avatar answered Oct 14 '22 09:10

John Topley