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!?
Can anyone help with this? It sounds like it would be a common task.
List R. 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!?
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 R. wrote:
Can anyone help with this? It sounds like it would be a common task.
List R. 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.
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.
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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.