# Select and link\_to edit

**URL:** <https://www.ruby-forum.com/t/select-and-link-to-edit/77610>\
**Category:** Rails\
**Created:** [November 29, 2006, 5:35am UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610 "2006-11-29T05:35:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosoft2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/94ad74/32.png) [@rosoft2001](https://www.ruby-forum.com/u/rosoft2001)\
**Post date:** [November 29, 2006, 5:35am UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610/1 "2006-11-29T05:35:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rosoft2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/94ad74/32.png) [@rosoft2001](https://www.ruby-forum.com/u/rosoft2001)\
**Post date:** [November 29, 2006, 2:46pm UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610/2 "2006-11-29T14:46:50Z")

</div>

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](http://chennairails.blogspot.com)

ok bye

---

<div class="post-metadata">

**Author:** ![rosoft2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/94ad74/32.png) [@rosoft2001](https://www.ruby-forum.com/u/rosoft2001)\
**Post date:** [November 29, 2006, 3:33pm UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610/3 "2006-11-29T15:33:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rosoft2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/94ad74/32.png) [@rosoft2001](https://www.ruby-forum.com/u/rosoft2001)\
**Post date:** [November 29, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610/4 "2006-11-29T17:23:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rosoft2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/94ad74/32.png) [@rosoft2001](https://www.ruby-forum.com/u/rosoft2001)\
**Post date:** [November 29, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/select-and-link-to-edit/77610/5 "2006-11-29T15:49:27Z")

</div>

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
