Bill Spornitz
2006-Jan-20 20:00 UTC
[Rails] 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 -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jan-20 20:32 UTC
[Rails] Re: Newbie: from the javascript way to the Rails way... Advi
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 > > -BillYou 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 -- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Jan-20 20:48 UTC
[Rails] Re: Newbie: from the javascript way to the Rails way... Advi
On 1/20/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote:> 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. >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.
Bill Spornitz
2006-Jan-20 22:02 UTC
[Rails] Re: Re: Newbie: from the javascript way to the Rails way...
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 <a href> tag in the html document, but I need to append to the url in this <a href> 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 -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jan-20 22:21 UTC
[Rails] Re: Re: Newbie: from the javascript way to the Rails way...
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 <a href> tag in the html document, but I need to append to the > url in this <a href> 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! > > -BillThe 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 -- Posted via http://www.ruby-forum.com/.
Reasonably Related Threads
- Worms Armageddon: cant open Worms Armageddon folder on fake ../drive_c/Team17/Worms Armageddon
- Armageddon
- armageddon vs. polling for shared resources, ajax, stale browsers
- Any free video (or audio) softphone VOIP client under Linux with touchscreen friendly interface ?
- [PATCH] gpu/drm: Remove duplicate headers