Spicing up your error pages can be the deciding factor on a sale or not. One of my clients wants just that, user friendly error pages and more sales. So I set off to test some ways to do so. What did I decide to do? Simple. All of my clients movies are tagged. So, I figured, we catch ActionController::RoutingError exceptions, split the request_uri and pass that array to acts_as_taggable_on to show possibly related movies. The problem, is I use authlogic and was experiencing the following fun error:
1 | ActionView::TemplateError (You must activate the Authlogic::Session::Base.controller with a controller object before creating objects) |
I scoured google, and found results for testing, which all stated, ‘add a before_filter :activate_authlogic’ and you should be good to go. I tried that, and it still didn’t work. It took me more debugging and I came to the realization that when an ActionController::RoutingError exception is thrown, it doesn’t call before_filters, after all, if you don’t know the controller to call, how can you run before_filters, even if it IS in the application controller. So, I simply moved it to the method I passed to rescue_from.
1 2 3 4 5 6 7 8 | rescue_from ActionController::RoutingError, :with => :page_not_found private def page_not_found activate_authlogic @possible = Title.find_tagged_with(request.request_uri.split('/'), :on => :tags, :limit => 5) render :template => "shared/page_not_found", :status => :not_found end |
Works fairly well, I’d say. If you have any recommendations or ideas on how to improve upon this basic concept, by all means, let me know.
Related posts: