Topic: Javascript calling :actions

What's the best way to assign an onClick= to an element that uses the :controller =>, :action => syntax? Basically, I want to blend javascript with rails routing. I've done a lot of searching around, but can't seem to find a solution.

Thanks for any help,
Jason

Re: Javascript calling :actions

Sometimes you add it in the 2nd hash. For example:

<%= link_to 'foo', { :action => 'bar' }, { :onclick => 'some js' } %>

But ultimately it depends on what element you are adding it to.

Railscasts - Free Ruby on Rails Screencasts

Re: Javascript calling :actions

This is specifically a <TR> with a bunch of <TD> elements. I wanted to add an onClick= to the <TR> so that you could click the row anywhere and call a :controller/:action. Using link_to to construct the complex <TR> seems like overkill. I was hoping to just attach some javascript to the <TR> like:
<tr onClick="url => { :controller => 'foo', :action => 'bar'})">

Is this even possible?

Re: Javascript calling :actions

I think you want url_for.

<tr onClick="<%= url_for :controller => 'foo', :action => 'bar' %>">

Also check out remote_function

Railscasts - Free Ruby on Rails Screencasts

Re: Javascript calling :actions

Ugh, I hate being a n00b. smile I forgot that helper existed. Thanks!