I am trying to make a row in a table link to the edit page. I know the links are being created, because I can print them out. I am close, but am missing something important. What do I change to make the link work properly?
<h1>Scouts</h1>
<p><%= button_to "Add a new Scout", new_scout_path, :method => :get %></p>
<div class="message-board">
<table>
<tr>
<th>Name</th>
<th>Rank</th>
<th>Advancement Date</th>
<th>Age</th>
</tr>
<% @scouts.each do |scout| %>
<tr <% link_to edit_scout_path(scout) %> >
<td><%= scout.name %></td>
<td><%= scout.rank %></td>
<td><%= scout.advancement %></td>
<td><%= scout.age %></td>
</tr>
<% end %>
</table>
</div>
As Robin said, that’s invalid HTML. You probably shouldn’t do that.
I personally would put an
onclickevent on thetrusing jQuery. Thetrelement would look like this:And then the associated JavaScript (placed in a file such as
app/assets/javascripts/scouts.js) would be something like this:This would make all
trelements that have adata-linkattribute act as if they were URLs in the most unobtrusive way I can think possible.