1

I'm using 1.2.2 of High Voltage, on a rails 3.2.2 app, and can't seem to get my app to fire a custom 404 when a page is not found - I just get the "Routing Error, No such page: " error page.

Routes.rb:

...

match '/signup',  to: 'users#new'

root :to => 'high_voltage/pages#show', :id => 'home'

match '/404', :to => 'errors#not_found'
match '/422', :to => 'errors#server_error'
match '/500', :to => 'errors#server_error'

match '/:id' => 'high_voltage/pages#show', :as => :static, :via => :get

I have also set the following in application.rb (which I believe is the Rails 3.2 way of kicking off the routing errors):

config.exceptions_app = self.routes

But I still get the default Routing Error page.

I've also tried using this in my app controller:

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
    end

    protected

    def render_500 exception
      logger.error exception.inspect
      render :template => "/errors/server_error.html.haml", :status => 500, :layout => 'application'
    end

    def render_404 exception
      logger.error exception.inspect
      render :template => "/errors/not_found.html.haml", :status => 404, :layout => 'application'
    end

But it still doesn't work.

I'm stumped! Can anyone help?

Les
  • 1,405
  • 15
  • 27

1 Answers1

2

I'm able to get a custom 404 page working with High Voltage with the following modifications:

Note: if you are testing locally you'll need to run RAILS_ENV=production rails s because development mode shows a different 404 error page.

# config/application.rb
config.exceptions_app = self.routes

# config/routes.rb
get '/404', to: 'errors#not_found'

Then we just need to create an ErrorsController and a view for errors/not_found.html.erb

harlow
  • 844
  • 9
  • 17