I''d like to be able to catch ActionController::MissingTemplate exceptions from within ActionControlle, *but*, MissingTemplate isn''t defined within my controllers!!! How is that possible - after all, all controller subclass ActionController, so how are exceptions it defines not there!? More importantly, how can I do this? -- Posted via http://www.ruby-forum.com/.
Can anyone help with this? It sounds like it would be a common task. List Recv wrote:> I''d like to be able to catch ActionController::MissingTemplate > exceptions from within ActionControlle, *but*, MissingTemplate isn''t > defined within my controllers!!! > > How is that possible - after all, all controller subclass > ActionController, so how are exceptions it defines not there!? > > More importantly, how can I do this?-- Posted via http://www.ruby-forum.com/.
Hi, I''m afraid that I don''t know all this well enough to accurately explain what (I think) is going on. Anyhow, it sounds like you''re doing: rescue MissingTemplate when you should be doing rescue ActionController::MissingTemplate more below: On 11-Dec-05, at 6:28 PM, List Recv wrote:> Can anyone help with this? It sounds like it would be a common task. > > List Recv wrote: >> I''d like to be able to catch ActionController::MissingTemplate >> exceptions from within ActionControlle, *but*, MissingTemplate isn''t >> defined within my controllers!!! >>Right. MissingTemplate is a class that''s defined in the ActionController module.>> How is that possible - after all, all controller subclass >> ActionController, so how are exceptions it defines not there!? >>No, all controllers subclass ActionController::Base (via ApplicationController). I.e. the class called "Base" in the ActionController module. Your code may be subclassing ActionController::Base but it has its *own* module namespace (probably the root namespace) so any time your code refers to a constant such as MissingTemplate it has to tell ruby the full name - ActionController::MissingTemplate. Bear in mind, all this has nothing to do with whether that error will actually propagate up to a point where your code can rescue it... And if I''m misunderstanding the true nature of your problem then perhaps you should re-post your question with example code so that people can get a better idea of what''s causing you grief. Regards, Trevor Trevor Squires http://somethinglearned.com
You can''t use a regular ''rescue'' keyword to rescue MissingTemplate exception. Use rescue_action instead, for example: def rescue_action(exception) if ::ActionController::MissingTemplate === exception render :text => ''rescued'' else super end end Kent. On Sunday 11 December 2005 21:28, List Recv wrote:> Can anyone help with this? It sounds like it would be a common task. > > List Recv wrote: > > I''d like to be able to catch ActionController::MissingTemplate > > exceptions from within ActionControlle, *but*, MissingTemplate isn''t > > defined within my controllers!!! > > > > How is that possible - after all, all controller subclass > > ActionController, so how are exceptions it defines not there!? > > > > More importantly, how can I do this?
On 12/11/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You can''t use a regular ''rescue'' keyword to rescue MissingTemplate exception. > > Use rescue_action instead, for example: > > def rescue_action(exception) > if ::ActionController::MissingTemplate === exception > render :text => ''rescued'' > else > super > end > end > > Kent.I''d suggest using rescue_action_in_public instead so you still get the stack trace while developing or accessing from the local machine. -- rick http://techno-weenie.net
One correction. If you use ActionController::MissingTemplate directly from within your controller action, you will get NameError (uninitialized constant Base). You have to explicitly set the global scope when you refer to framework classes like so ::ActionController::MissingTemplate. Kent. On Sunday 11 December 2005 22:16, Trevor Squires wrote:> Hi, > > I''m afraid that I don''t know all this well enough to accurately > explain what (I think) is going on. > > Anyhow, it sounds like you''re doing: > > rescue MissingTemplate > > when you should be doing > > rescue ActionController::MissingTemplate > > more below: > > On 11-Dec-05, at 6:28 PM, List Recv wrote: > > Can anyone help with this? It sounds like it would be a common task. > > > > List Recv wrote: > >> I''d like to be able to catch ActionController::MissingTemplate > >> exceptions from within ActionControlle, *but*, MissingTemplate isn''t > >> defined within my controllers!!! > > Right. MissingTemplate is a class that''s defined in the > ActionController module. > > >> How is that possible - after all, all controller subclass > >> ActionController, so how are exceptions it defines not there!? > > No, all controllers subclass ActionController::Base (via > ApplicationController). I.e. the class called "Base" in the > ActionController module. > > Your code may be subclassing ActionController::Base but it has its > *own* module namespace (probably the root namespace) so any time your > code refers to a constant such as MissingTemplate it has to tell ruby > the full name - ActionController::MissingTemplate. > > Bear in mind, all this has nothing to do with whether that error will > actually propagate up to a point where your code can rescue it... > > And if I''m misunderstanding the true nature of your problem then > perhaps you should re-post your question with example code so that > people can get a better idea of what''s causing you grief. > > Regards, > Trevor > > Trevor Squires > http://somethinglearned.com > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Good point. Thanks. Kent. On Sunday 11 December 2005 23:17, Rick Olson wrote:> > I''d suggest using rescue_action_in_public instead so you still get the > stack trace while developing or accessing from the local machine. >
Kent Sibilev wrote:> One correction. If you use ActionController::MissingTemplate directly > from > within your controller action, you will get NameError (uninitialized > constant > Base). You have to explicitly set the global scope when you refer to > framework classes like so ::ActionController::MissingTemplate. > > Kent.Fascinating. I found the same thing with the rescue_action_in_public in the Rails Book - you need to do case ::ActionController::RoutingError. Could you explain a) why this is so and b) the usage of :: without being preceded by a module? -- Posted via http://www.ruby-forum.com/.