Hi there, I do think this is a simple but when we dont know how, it is not simple at all. I have got a shopping cart and URL to show it is something like .../shop/cart/edit, and in the template cart.rhtml, I have some buttons to increment, decrement, remove items in the cart, accordingly in the cart controller, I have a method for each button, for instance, def increment ... render :action=>''edit'' end It works! However in the browser, the URL is changed from .../shop/cart/edit to .../shop/cart/increment/[item id]. Then if I click on refresh button in the browser, the increment action will be redone, that''s what I want to prevent. What I want exactly is I would like to see the URL .../shop/cart/edit unchanged after the buttons are clicked. I know, I can call redirect_to instead of render, but performance would not be the same. Any idea and hit are greatly appreciated. Thanks! Franck -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10 Oct 2007, at 11:17, Franck Yu wrote:> > def increment > ... > render :action=>''edit'' > end > > It works! However in the browser, the URL is changed from > .../shop/cart/edit to .../shop/cart/increment/[item id]. Then if I > click > on refresh button in the browser, the increment action will be redone, > that''s what I want to prevent. What I want exactly is I would like to > see the URL .../shop/cart/edit unchanged after the buttons are > clicked. > I know, I can call redirect_to instead of render, but performance > would > not be the same. Any idea and hit are greatly appreciated. Thanks! >That''s not possible. If the way the browser gets to it is /shop/cart/ increment/[item id] then that''s the url you''ll get, unless you do a redirect An alternative would be to use ajax, which won;t change the url and won''t result in a refresh repeating the action. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Franck Yu wrote:> Hi there, > I do think this is a simple but when we dont know how, it is not simple > at all. > I have got a shopping cart and URL to show it is something like > .../shop/cart/edit, and in the template cart.rhtml, I have some buttons > to increment, decrement, remove items in the cart, accordingly in the > cart controller, I have a method for each button, for instance, > > def increment > ... > render :action=>''edit'' > end > > It works! However in the browser, the URL is changed from > .../shop/cart/edit to .../shop/cart/increment/[item id]. Then if I click > on refresh button in the browser, the increment action will be redone, > that''s what I want to prevent. What I want exactly is I would like to > see the URL .../shop/cart/edit unchanged after the buttons are clicked. > I know, I can call redirect_to instead of render, but performance would > not be the same. Any idea and hit are greatly appreciated. Thanks! > > > Franckuse ajax. incidentally, i would highly recommend u download (as far as i know the only one around) the substruct ror commerce code - can learn a lot from it (code is highly written) as the best way to learn code is to learn from reading existing projects. aside from that i''m sure there are parts there u can use in your app (CTR-c) if u place them in the right spots | modify the code slightly for u''r specific needs. either way, it is also a great opportunity to progress into good programming as well. here: http://dev.subimage.com/projects/substruct/wiki/InstallingSubstruct (the code is buried deep in the vendor directory, but it''s not a problem finding it) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
((regarding substruct)) the installation can be a pain, but whatever doesn''t kill ya, strengthens thee. worth checking out. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Fred and Shai, Thank you very much for your reply! I agree with you: Ajax is the right solution that I will implement in the following days. And thank you again for your help! Franck __________________________ Shai Rosenfeld wrote:> use ajax. > > incidentally, i would highly recommend u download (as far as i know the > only one around) the substruct ror commerce code - can learn a lot from > it (code is highly written) as the best way to learn code is to learn > from reading existing projects. > > aside from that i''m sure there are parts there u can use in your app > (CTR-c) if u place them in the right spots | modify the code slightly > for u''r specific needs. > > either way, it is also a great opportunity to progress into good > programming as well. here: > > http://dev.subimage.com/projects/substruct/wiki/InstallingSubstruct > > (the code is buried deep in the vendor directory, but it''s not a problem > finding it)-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello, FYI, you will need to use redirect_to in conjunction with AJAX to ensure that you are backwards compatible with non-javascript enabled browsers. So, for example: def increment ... redirect_to :action => :edit unless request.xhr? end This would fire the edit action fire and display edit view after increment is executed. This would ensure that the URL does not change. Additionally, you would have a view called increment.rjs which is the ruby-javascript code to update the DOM for the AJAX side of things. Regards, Jason Arora On Oct 10, 3:17 am, Franck Yu <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi there, > I do think this is a simple but when we dont know how, it is not simple > at all. > I have got a shopping cart and URL to show it is something like > .../shop/cart/edit, and in the template cart.rhtml, I have some buttons > to increment, decrement, remove items in the cart, accordingly in the > cart controller, I have a method for each button, for instance, > > def increment > ... > render :action=>''edit'' > end > > It works! However in the browser, the URL is changed from > .../shop/cart/edit to .../shop/cart/increment/[item id]. Then if I click > on refresh button in the browser, the increment action will be redone, > that''s what I want to prevent. What I want exactly is I would like to > see the URL .../shop/cart/edit unchanged after the buttons are clicked. > I know, I can call redirect_to instead of render, but performance would > not be the same. Any idea and hit are greatly appreciated. Thanks! > > Franck > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Jason, Thank you for your input! It is very helpful! Actually I did not think about backwards compatibility. By the way, I found that how to change URL in browser without reloading the page is a general issue and the only solution seems in AJAX. Franck jasoo24 wrote:> Hello, > > FYI, you will need to use redirect_to in conjunction with AJAX to > ensure that you are backwards compatible with non-javascript enabled > browsers. > > So, for example: > > def increment > ... > redirect_to :action => :edit unless request.xhr? > end > > This would fire the edit action fire and display edit view after > increment is executed. This would ensure that the URL does not change. > > Additionally, you would have a view called increment.rjs which is the > ruby-javascript code to update the DOM for the AJAX side of things. > > Regards, > Jason Arora > > > > On Oct 10, 3:17 am, Franck Yu <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---