Forum: Ruby on Rails make a <tr>clickable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-04-01 06:39
I would like to make an entire table row clickable so the user will be
directed to another url. If i was using hand written javascript i would
just add an onclick to the <tr>, but i want to use rails routes and to
be able to pass in parameters from ruby. What is the best way to
accomplish this?

<tr onclick = <%= link_to my_route_path %> > <td>content</td></tr>
832c11f394e33ac2b2b62dcc2275bd9c?d=identicon&s=25 Daniel Liebig (dli)
on 2009-04-01 10:00
Richard Schneeman wrote:
> I would like to make an entire table row clickable so the user will be
> directed to another url. If i was using hand written javascript i would
> just add an onclick to the <tr>, but i want to use rails routes and to
> be able to pass in parameters from ruby. What is the best way to
> accomplish this?
>
> <tr onclick = <%= link_to my_route_path %> > <td>content</td></tr>

onclick="window.location.href = '<%= url_for :controller => ':foo'
:action => 'bar' %>'

see: http://api.rubyonrails.org/
see:
http://api.rubyonrails.org/classes/ActionControlle...

D.
4fe6f4cffa89394426a0b027e22809f0?d=identicon&s=25 HeChian (Guest)
on 2009-04-01 10:28
(Received via mailing list)
I think you can make it done by jQuery or Prototype with CSS Selector:

<tr class="clickable" rel="<%= my_route_path %>"><td>content</td></tr>

<script>
(function($){
$('tr.clickable').click(function(){ // You can use .live('click',
function(){}) if you use jQuery 1.3.1 or higher
  // Link to ...
});
})(jQuery);
</script>

On 4月1日, 下午12時39分, Richard Schneeman <rails-mailing-l...@andreas-
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2009-04-09 06:06
Thanks, both work great! Though i guess neither would degrade well with
javascript turned off. Guess you cant have your clickable-rows and eat
them too ^_^
This topic is locked and can not be replied to.