Forum: Ruby on Rails How can I use form fields in link_to parameters?

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.
gattox (Guest)
on 2007-06-18 18:07
(Received via mailing list)
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.
Bill W. (Guest)
on 2007-06-18 19:27
(Received via mailing list)
Hi gattox,

gattox wrote:

> Don't know how to use a link_to directive where one
> of the parameters is taken form a form field (client side), eg:
<snip>
> $('numrows').value
I can't think of any way to do this with link_to.  Remember that link_to
is
a server-side helper method that's generating an html <a ...> tag to
send to
the client.  There might be a way to use client-side javascript to
modify
the tag, but it doesn't feel like a Rails-ish approach to me.

If it were me, I'd ditch the link-based submission and just use
observe_field on the text_field or drop-down (select) to trigger the
repagination action.

hth,
Bill
This topic is locked and can not be replied to.