0

how to make the rows of my user index view which i generated using scaffolding, to work as a hyperlink to the show user action. after clicking anywhere on the user row it will show us the corresponding user.
it is also acceptable if i can make link to a division.

code

<table>
  <tr>
  <th>Username</th>
  <th></th>
  <th>email</th>
  <th>roll_no</th>
</tr>

<% @users.each do |user| %>
  <tr >//i want to make these rows as link
    <% if user.username!='admin' %>
      <td><%= user.username %></td>
      <td><%= user.email %></td>
      <td><%= user.roll_no %></td>
      <td><%= link_to 'show', @user %></td><br/>
      <td><%= link_to 'Delete', user, confirm: 'Are you sure?', method: :delete %></td>
    <% end %>
  </tr>
user229044
  • 232,980
  • 40
  • 330
  • 338
Super Engineer
  • 1,966
  • 1
  • 13
  • 21
  • You can't without JavaScript. Your `@users.each` is also missing an `end`. Finally, I've edited your question to correctly indent the code. Please review my edits and stop using `
    ` tags and back-ticks to format *blocks* of code. Just select the code and click the `{}` button, or indent the entire block by 4 spaces.
    – user229044 Apr 10 '12 at 17:39

1 Answers1

2

As meager said, you should use JavaScript. Something like this:

$('tr').click(function(){
    document.location.href='the_link_to_go_to';
})

You can modify it to suit your needs.

Timur
  • 162
  • 1
  • 1
  • 5