简体   繁体   中英

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

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

<%= link_to({:controller =>  "events", :action => "search", :category => @favorites[0].name}) do %>
   <div> 
     <%= @favorites[0].name %> 
   </div>
<%end%> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM