Forum: Ruby on Rails Dynamic parameters in link_to

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
63be0db1917c0299628460cab2177aaa?d=identicon&s=25 Roberto Gattinoni (gattox)
on 2007-06-18 15:25
Don't know how to use a link_to directive where one of the parameters is
taken form a form field (client side), eg:

...
#
# The field "numrows" is used to dynamically change the number of rows
per page
# in a pager (ok, let apart will_paginate and other paginate plugins)
#
<label for="numrows">#Rows per Page : </label>
<%= text_field_tag "numrows",  session[:nr] || Customer.per_page, :size
=> 5 %>
<%= link_to 'Change #Rows per Page', {:action => 'set_row_per_page',
:rowsperpage => <would like to pass here the content of "numrows"
field>, :method => :post, :class => "IsALink"  %>

Note that "numrows" is a non-model field of the form.

How can i dynamically set the value of ":rowsperpage" so that clicking
on the link  will restart pagination with a differente number of rows
per page. I need to know how to dynamically set up the value of the
parameter using something link $('numrows').value

Any help appreciated.
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 Michael Latta (Guest)
on 2007-06-18 17:49
(Received via mailing list)
You will need to use client side javascript to construct the value
you want to pass.  You need to use link_to_function to make the link
call javascript, compute the URL including parameters, then either
fetch or redirect to that URL.

Michael
This topic is locked and can not be replied to.