Hi, I have a partial which is being rendered in a view in controller A. This partial has a form which calls ''update'' action in controller B. If update fails I have the render back the original view again with the proper errors. I used, render :action => :show This show action is actually is that of controller B but the call being ajax it is not loaded and the original view continues to be displayed but the errors are not being shown. The problem is I am not able to detect the errors being received if any. Need suggestions urgently Regards, Sumit. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Y61TT1YJ_GYJ. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-May-10 03:22 UTC
Re: Sending errors in response when using ''render''
On Thu, May 9, 2013 at 11:59 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have a partial which is being rendered in a view in controller A. This > partial has a form which calls ''update'' action in controller B. If update > fails I have the render back the original view again with the proper errors. > I used, > > render :action => :show > > This show action is actually is that of controller B but the call being ajax > it is not loaded and the original view continues to be displayed but the > errors are not being shown. > > The problem is I am not able to detect the errors being received if any.Let me see if I understand. 1) A is a controller that renders an standard HTML view of some type (ERB, HAML, etc). 2) B is a controller that is called by the page A renders as AJAX, returning JSON data. If controller B fails for some reason, you need to inform your client side application of the failure, typically this is also done be returning JSON with an error code and message, plus any other information needed for the client-side application to recover gracefully (and inform the user if necessary). Meanwhile, controller B should also be logging information about it''s state to the Rails.logger, thus giving you a place to put information for later debugging, if necessary. So: any controller called by AJAX should *always* return JSON, either the expected result, or an error object. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.