views:

439

answers:

3

How do I wrap a link around view code? I can't figure out how to pass multiple lines with ruby code to a single link_to method. The result I am looking for is that you click the column and get the show page:

<div class="subcolumns">
  <div class="c25l">
     <div class="subcl">
        <%= image_tag album.photo.media.url(:thumb), :class => "image" rescue nil  %>
     </div>
    </div>
  <div class="c75r">
     <div class="subcr">
      <p><%= album.created_at %></p>
      <%= link_to h(album.title), album %>
      <p><%= album.created_at %></p>
      <p><%= album.photo_count %></p>
     </div>
  </div>
</div>
+3  A: 

You can use link_to with a block:

<% link_to(@album) do %>
    <!-- insert html etc here -->
<% end %>
Barry Gallagher
only in >= Rails 2.2
Omar Qureshi
Ah, ok I wasn't aware of that! Thanks Omar.
Barry Gallagher
+6  A: 

link_to takes a block of code which it will use as the body of the tag.

So, you do

<% link_to(@album) do %>
  html-code-here
<% end %>

But I'm quite sure that to nest a DIV inside a A-tag is not valid HTML.

Thorbjørn Hermansen
+2  A: 

For older Rails versions, you can use

<% content_tag(:a, :href => foo_path) do %>
  <span>Foo</span>
<% end %>
Omar Qureshi