Newbie: from the javascript way to the Rails way... Advice?

Hello;

I’m building an application for a touchscreen that pages through a set
of survey pages. On each page, the user makes some choices by touching
items on the screen (words, or images) and, when satisfied with their
choices, clicks the Next page button.

Rails has done a great job helping me get things to the screen, and
paginating for me… but I’m stuck on something that I’ve implemented
before in plain old javascript:

When a user touches an item, in the old days I would simply write a
string to the end of the window.location.href:

function addThisToo(key, value)
{
window.location.href += “&” + key + “=” + value
}

and, at some point later on, submit this, and there you go…

My experience with Rails, so far, has been that there are remarkably
sensible solutions for many of web work’s little problems… is there a
Rails solution for this one? (My preference is for a non-AJAX solution
at this point…)

thanks to all

-Bill

Bill Spornitz wrote:

Hello;

I’m building an application for a touchscreen that pages through a set
of survey pages. On each page, the user makes some choices by touching
items on the screen (words, or images) and, when satisfied with their
choices, clicks the Next page button.

Rails has done a great job helping me get things to the screen, and
paginating for me… but I’m stuck on something that I’ve implemented
before in plain old javascript:

When a user touches an item, in the old days I would simply write a
string to the end of the window.location.href:

function addThisToo(key, value)
{
window.location.href += “&” + key + “=” + value
}

and, at some point later on, submit this, and there you go…

My experience with Rails, so far, has been that there are remarkably
sensible solutions for many of web work’s little problems… is there a
Rails solution for this one? (My preference is for a non-AJAX solution
at this point…)

thanks to all

-Bill

You can add custom parameters to links like this…

link_to “Do Not Push!”, {:controller=>‘world’, :action=>‘rotation’,
:speed=>“stop”}, :post=>true, :confirm=>“Are you sure? There is no
Undo!”

This will map to

http://www.armageddon.com/world/rotation/?speed=stop

or something similar.

_Kevin

On 1/20/06, Kevin O. [email protected] wrote:

before in plain old javascript:

link_to “Do Not Push!”, {:controller=>‘world’, :action=>‘rotation’,
:speed=>“stop”}, :post=>true, :confirm=>“Are you sure? There is no
Undo!”

This will map to

http://www.armageddon.com/world/rotation/?speed=stop

or something similar.

In addition to this (good) suggestion, you can use named routes and
routing variables to make this cleaner.
http://wiki.rubyonrails.org/rails/pages/NamedRoutes
The above would then be:
link_to “Do Not Push”, stop_button_url(:speed => ‘stop’, :post =>
true, :confirm => “Are you sure?”)
…which lets you omit the :action and :controller options.

Thank you for these excellent responses!

The main hurdle, as I see it, is that I need the browser to append stuff
to the url at the client end; as I understand it, the link_to function
creates a tag in the html document, but I need to append to the
url in this
tag, based on user interaction, at the browser. The
actual string appended is based on which selections the user makes. Am I
seeing this incorrectly? Will link_to accomodate this?

Thanks again!

-Bill

Bill Spornitz wrote:

Thank you for these excellent responses!

The main hurdle, as I see it, is that I need the browser to append stuff
to the url at the client end; as I understand it, the link_to function
creates a tag in the html document, but I need to append to the
url in this
tag, based on user interaction, at the browser. The
actual string appended is based on which selections the user makes. Am I
seeing this incorrectly? Will link_to accomodate this?

Thanks again!

-Bill

The link_to will fix the link at render time. AJAX would be an easy way
to do what you want, just have it observe the fields the user can change
and have it update the link as needed.

_Kevin