Forum: Ruby on Rails Passing a JavaScript variable through a Rails params hash

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.
Jon H. (Guest)
on 2009-05-25 04:40
Hi guys, hoping someone can give me a pointer with this?

I have a Javascript variable that I'm updating dynamically as a user
interacts with the page. I want the user to be able to save it's value
at any time along with some text data in a pop-up form, so the best way
I can think of is to pass it through the params hash without writing it
into the form. I'm not totally sure how to do this though?

The only practical solution i've got is for a hidden field line in the
form to be dynamically generated when the user goes to save it, but this
feels like overkill to me. Does anyone have any suggestions for a neater
way to do it?

Thanks,

Jon
Julian L. (Guest)
on 2009-05-25 06:04
(Received via mailing list)
Hi

You need to change the target attrubute of the form tag. Give it an id
if it doesn't have one:
form_tag({:action =>"update"}, {:id => "the_form"}) do
...
Then if using prototype, $('the_form').target += '&varname='+var;

Mind you URL encode the params value. You can use the escapeHTML
string class to encode it properly if using prototype. I think there
is also an escape function ;)

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails
deploy process! Check it out now!


On 25/05/2009, at 10:40 AM, Jon H. <rails-mailing-list@andreas-
This topic is locked and can not be replied to.