select and link_to edit

I have a select box like:

<%= select('tournament', 'name', Tournament.find_all.collect
{|tournament|}) %>

and I want to place a link_to near it to Edit, like

<%= link_to 'Edit, :action => 'edit' %>

to edit just one of the options at a time.

Any idea?



You can either use javascript magick to redirect to currently selected item
edit page or instead of 'edit' link put 'edit' submit button and submit to
action that will e.g. do redirect to item's edit page.

I still want to be a link, so I had the javascript idea too. I know how
to do it in pure js, but here it's another controller involved and I
don't know how to build the link for that redirect, not how to get the
selected value.

Any idea?


Maxim Kulkin wrote:

Well, I guess, there is no support for such things in Rails yet. Here is my
hack for it:

def dynamic_link_to(title, url_options, html_options = {})
  with_option = html_options[:with] || {}
  html_options.delete :with

  with_options.each { |param, element_id| url_options[param]
= "dynamic_#{param}" }

  url = url_for(url_options)

  with_options.each { |param, element_id| url.gsub!
("dynamic_#{param}", "'+$F('#{element_id}')+'") }

  link_to title, '#', html_options.merge({ :onclick => "window.location
= '#{url}';"})

To use it you should do

<select name="my_value">
<%= dynamic_link_to 'Edit', {:controller => 'foo', :action => 'edit'}, :with
=> { :id => 'my_value' } %>

The link should look something like this:

<a href='#' onclick="window.location
= '/foo/'+$F('my_value')+'/edit';">Edit</a>

PS check the code, I wrote it by memory.. haven't got sources at hand.. But I
guess, I'll get the idea