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