Select and link_to edit

I have a select box like:

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

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?

Thanks,

ro

rosoft2001 wrote:

I have a select box like:

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

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?

Thanks,

ro

Hi,

you just grab the selected value in Edit method

by using
params[:tournament][‘name’]

in the edit method.

from that method you can do whatever you want.

I hope you understand
for more Rails related Links Visitthe following links
http://chennairails.blogspot.com

ok bye

On 29 November 2006 07:34, rosoft2001 wrote:

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.

On 29 November 2006 17:32, rosoft2001 wrote:

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?
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}’;”})
end

To use it you should do

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

The link should look something like this:

Edit

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

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?

Thanks,
ro