0

I have a table that links to a customer show page

_table.html.erb

<table class="table table-striped table-bordered table-hover table-condensed">
  <thead>
    <tr>
      <th width="50"><%= sort_link @q, :id, "ID"%></th>
      <th width="50"><%= sort_link @q, :health_status_ok, "Status"%></th>
      <th width="50"><%= sort_link @q, :first_name, "First Name"%></th>
      <th width="50"><%= sort_link @q, :last_name, "Last Name"%></th>
      <th>Tickets Enabled</th>
      <th>Notes</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% @customers.each do |customer| %>
      <a href="<%= customer_path(customer) %> ">
        <tr data-link="<%= customer_path(customer) %>">
          <td>&nbsp;&nbsp;&nbsp;<%= customer.id %></td>
          <td>&nbsp;&nbsp;<i class="<%= status_code_css(customer.health_status_ok)%>"></i></td>
          <td><%= customer.first_name  %></td>
          <td><%= customer.last_name  %></td>
          <%= ( render 'customers/auto_ticket_enable', customer: customer ) if AUTHORIZED_USERS.include?(session[:current_user_login])%>
          <td><%= customer.notes.nil? ? "" : customer.notes  %></td>
          <td><%= link_to "View", customer_path(customer), class: 'btn center-block' %></td>
        </tr>
      </a>
    <% end %>
  </tbody>
</table>

When the page renders, the row is not clickable. The source looks like this of one instance.

...
<tbody>
      <a href="/customers/11 ">
        <tr data-link="/customers/11">
          <td>&nbsp;&nbsp;&nbsp;11</td>
          <td>&nbsp;&nbsp;<i class="fa fa-check-circle fa-2x status-ok"></i></td>
          <td>Some</td>
          <td>Dude</td>
            <td style="color:green"><strong>Enabled</strong></td>

          <td>123 Anyplace you want. </td>
          <td><a class="btn center-block" href="/customers/11">View</a></td>
        </tr>
      </a>
...

How do I make the entire row a clickable link. What am I missing?

R.J. Robinson
  • 2,180
  • 3
  • 21
  • 33
  • possible duplicate of [Making a Table Row clickable](http://stackoverflow.com/questions/197713/making-a-table-row-clickable) – davegson Sep 09 '15 at 13:09

1 Answers1

1

I don't believe you can put a <tr> inside an <a> tag.

I see you're using Bootstrap. See this StackOverflow post for how to do make a table row clickable using jQuery, which is included with Bootstrap.

Community
  • 1
  • 1
madcow
  • 2,567
  • 14
  • 31