Hi, I''ve asked this before, but I wasn''t sure what I was looking for and what the problem was back then. What I want is to be able to tell Rails that after -every- AJAX- request, some default RJS gets executed. I''ve tried using an after_filter rendering an rjs-file, but because all of my methods already use RJS, Rails produces an error similar to when you use two redirects in one request. I can, of course, add some code to every file, but that wouldn''t be very DRY. How can I tell Rails, just like you do with your application layout for example, to do some general stuff in addition to the specific code in my .rjs files? Thank you!
Anyone? I plan on implementing error reporting in my app at the end of this week and I could really use your thoughts on this. On 11 okt, 14:24, jhaagmans <jaap.haagm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''ve asked this before, but I wasn''t sure what I was looking for and > what the problem was back then. > > What I want is to be able to tell Rails that after -every- AJAX- > request, some default RJS gets executed. I''ve tried using an > after_filter rendering an rjs-file, but because all of my methods > already use RJS, Rails produces an error similar to when you use two > redirects in one request. I can, of course, add some code to every > file, but that wouldn''t be very DRY. > > How can I tell Rails, just like you do with your application layout > for example, to do some general stuff in addition to the specific code > in my .rjs files? > > Thank you!
jhaagmans wrote:> Anyone? I plan on implementing error reporting in my app at the end of > this week and I could really use your thoughts on this.You could.. Override the class definitions for those calls and hard-code something like: :after => "run this" ... I''m talking from a deep and dark place here, where the sun doesn''t shine much, but I can''t really see another solution. -- Posted via http://www.ruby-forum.com/.
But it can''t be that I''m the only one who wants to implement such functionality! It''s something every Rails programmer using AJAX calls will face, isn''t it? How do those people handle centralized error messages? Do they just add code to every rjs file? On 12 okt, 21:50, Aldric Giacomoni <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> jhaagmans wrote: > > Anyone? I plan on implementing error reporting in my app at the end of > > this week and I could really use your thoughts on this. > > You could.. Override the class definitions for those calls and hard-code > something like: > :after => "run this" > ... > > I''m talking from a deep and dark place here, where the sun doesn''t shine > much, but I can''t really see another solution. > -- > Posted viahttp://www.ruby-forum.com/.
jhaagmans wrote:> But it can''t be that I''m the only one who wants to implement such > functionality! It''s something every Rails programmer using AJAX calls > will face, isn''t it? How do those people handle centralized error > messages? Do they just add code to every rjs file?If you use validations, won''t Rails just return error messages in the HTML anyway?> > On 12 okt, 21:50, Aldric Giacomoni <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
It will return error messages like any other Rails requests, but it won''t update your flash, so the only thing that happens is that it returns an error. You won''t be able to show it if you can''t update the page. What I''ll do now, for the time being: def create @item = Item.new(params[:item]) if @item.save #render all kinds of things else @item.report_errors end end private def report_errors flash[:warning] = this.errors.full_messages.join("<br />") render :action => "update_errors.rjs" end But I have a feeling this isn''t as DRY as it can be. On 13 okt, 16:12, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> jhaagmans wrote: > > But it can''t be that I''m the only one who wants to implement such > > functionality! It''s something every Rails programmer using AJAX calls > > will face, isn''t it? How do those people handle centralized error > > messages? Do they just add code to every rjs file? > > If you use validations, won''t Rails just return error messages in the > HTML anyway? > > > > > On 12 okt, 21:50, Aldric Giacomoni <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.