如何在RoR中使用content_tag嵌入标签?

时间:2022-10-27 07:53:01

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:

我希望它显示在td标签中,所以我想使用这个content_tag来帮助我:

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

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

我想要我的td中的超链接,所以我有这样的东西:

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

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

但是我得到了语法错误,我该怎么办?

1 个解决方案

#1


22  

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 %>

#1


22  

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 %>