def edit @product = Product.find(params[:id]) end def update @product = Product.find(params[:id]) if @product.update_attributes(params[:product]) flash[:notice] = ''Product was successfully updated.'' redirect_to :action => ''show'', :id => @product else render :action => ''edit'' end end when errors happen, to avoid showing update in the address bar, i have to redirect to edit. but the problem is the error message is lost. any suggestion/workaround so that i can catch and display the error message on the redirected page? this should be a basic problem for rails :) thanks in advance -- 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 -~----------~----~----~----~------~----~------~--~---
use flash.keep to retain flash messages across multiple requests. stick that right before your redirect. Adrian Liem wrote:> def edit > @product = Product.find(params[:id]) > end > > def update > @product = Product.find(params[:id]) > if @product.update_attributes(params[:product]) > flash[:notice] = ''Product was successfully updated.'' > redirect_to :action => ''show'', :id => @product > else > render :action => ''edit'' > end > end > > > when errors happen, to avoid showing update in the address bar, i have > to redirect to edit. but the problem is the error message is lost. any > suggestion/workaround so that i can catch and display the error message > on the redirected page? this should be a basic problem for rails :) > thanks in advance > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Norris wrote:> use flash.keep to retain flash messages across multiple requests. > stick that right before your redirect.ah, forget to mention, the flashes works fine. the problem is within the error_messages_for() and the error_message_on() scope. thanks for the answer :) -- 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 -~----------~----~----~----~------~----~------~--~---
Can you do something like def edit if request.post? if update flash and redirect to show end end end Then put update under protected and have it return false if there''s an error. That way there''s no redirect when you have an error. I''m pretty noob-ish at rails, but I like trying to respond to posts to help me learn. So if this isn''t what you want, I apologize. Jason Adrian Liem wrote:> Jason Norris wrote: > >> use flash.keep to retain flash messages across multiple requests. >> stick that right before your redirect. >> > > ah, forget to mention, the flashes works fine. the problem is within the > error_messages_for() and the error_message_on() scope. thanks for the > answer :) > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Norris wrote:> Can you do something like > > def edit > if request.post? > if update > flash and redirect to show > end > end > end > > Then put update under protected and have it return false if there''s an > error. That way there''s no redirect when you have an error. > > I''m pretty noob-ish at rails, but I like trying to respond to posts to > help me learn. So if this isn''t what you want, I apologize. > > Jasonthat''s very nice, no need to apologize please, i''m pretty new in rails too, about 3 weeks :) that can do, but no, i don''t think i would do that, because it will constraint what post-action-methods (like update, create, destroy) should be in the page-action-methods (like edit, new, show), so it won''t be very flexible. i don''t think this is the DRY solution, and don''t you think it''s kinda hard to maintain later, since everytime we add/remove a post-action-method, we have to edit the page-action-methods as well. thanks in advance Adrian Liem -- 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 -~----------~----~----~----~------~----~------~--~---