Acrux
Acrux

Reputation: 406

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.

Upvotes: 1

Views: 521

Answers (1)

Nitin Srivastava
Nitin Srivastava

Reputation: 1424

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

Upvotes: 3

Related Questions