[英]ruby on rails wrap block of code in link_to
Hello I have this link_to and I can't figure out how to wrap a block of html code in it such that the div inside the link_to becomes a link. 您好,我有这个link_to,我不知道如何包装其中的html代码块,以使link_to内的div成为链接。 I have this code:
我有以下代码:
<%= link_to @favorites[0].name, {:controller => "events", :action => "search", :category => @favorites[0].name} %>
I have tried using "do" then <%end%> but I can't make it work. 我尝试使用“ do”,然后使用<%end%>,但无法使其正常工作。
<%= link_to @favorites[0].name, {:controller => "events", :action => "search", :category => @favorites[0].name} do %>
<div> CODE HERE</div>
<%end%>
Any ideas on how to do this? 有关如何执行此操作的任何想法? I do not understand the syntax.
我不了解语法。
You need to give only path
with link_to
when using the block
. 使用
block
时,您只需要提供link_to
path
。
<%= link_to({:controller => "events", :action => "search", :category => @favorites[0].name}) do %>
<div>
<%= @favorites[0].name %>
</div>
<%end%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.