How to setup a 404 page? #23

frarees opened this Issue Sep 27, 2011 · 9 comments


None yet

6 participants


I've been looking on how to set this up to render a page when a template is not found. Can anyone help me with this? Thank you all.

thoughtbot, inc. member

So when someone requests a non-existent page that hits the high voltage controller, you want to render something other than the 404.html page?


When it doesn't find the page, it renders a message like: Cannot find page: /page/foo

I want it to render my custom 404 page, but I don't get a clue about how to do it.

thoughtbot, inc. member

If you look here, you can see what it's doing -

If you try to handle an ActionController::RoutingError in your custom 404, will that work?

@mjankowski mjankowski closed this Oct 12, 2011

So, if i want to get 404.html served by high_voltage, I need a custom PagesController?

I would like to remove public/404.html and add /app/pages/404.hml, but I underestand that doesn't work like this.

Am I right?

thoughtbot, inc. member

Rendering a dynamic 404 page in rails is not necessarily related to high_voltage, if that's what you want. Check out the rescue_from method - - that might help.

If you ARE trying to add 404 customization to high_voltage, can you be more specific about what you want to do?


Since high_voltage is an engine there seems to be a problem using the normal rescue_frommethod. Therefor it would be nice to at least have the option to have a default page which would be rendered when no page was matched.

this gem seems to fix the problem


@mjankowski, what i was trying to do was use high_voltage to render a dynamic 404.

As you say, this can be achieved without high_voltage, this is what I have in application_controller.rb:

unless config.consider_all_requests_local
  rescue_from Exception, :with => :render_500
  rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  rescue_from ActionController::RoutingError, :with => :render_404
  rescue_from ActionController::UnknownController, :with => :render_404
  rescue_from ActionController::UnknownAction, :with => :render_404


def render_500 exception
  logger.error exception.inspect
  render :template => "/pages/500.html.erb", :status => 500, :layout => 'static'

def render_404 exception
  logger.error exception.inspect
  render :template => "/pages/404.html.erb", :status => 404, :layout => 'static'

Thank you!


Sorry to ressurect such an old issue, but I've tried to implement this the way @dormi suggests and HV doesn't seem to catch the "rescue_from ActionController::RoutingError, :with => :render_404" in my application controller.

I get the vanilla error page with page not found.

I've also tried the suggestion from @Godisemo and the vidibus page about using the config.exceptions_app = self.routes trick - but that doesn't work at all.

I'm on Rails 3.2.11 and HV 1.2.2...


It is depend on particular use case, but in case someone looking to simply handle invalid pages:

class PagesController < ApplicationController
  include HighVoltage::StaticPage

  def invalid_page
    render('pages/404-error', :status => 404)

Please see "Override" scection for more details about PagesController:

invalid_page is the method from HighVoltage::StaticPage module, which, by default, raises ActionController::RoutingError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment