-1

I am facing the routing error if the route is not match. I want to redirect the page to 404 static page if the route not match. I used some references but it's not working. The following error is displayed when No route matches. No route matches [GET] "/userss"

Rails.root: D:/Ruby/Assignment/Library

Dilip Kale
  • 71
  • 7
  • You will get it (no route matches ....) on development environment but no on production environment, if you want to render 404 try read this question http://stackoverflow.com/questions/4156490/how-to-test-500-html-in-rails-development-env – itx Dec 16 '16 at 06:55

2 Answers2

0

At the end of your routes.rb file write

  get      '*path'       => redirect('your path of static page')
kajal ojha
  • 1,248
  • 8
  • 20
-2

Add these lines in your application_controller.rb

rescue_from ActionController::RoutingError, with: :render_404

private

def render_404
  respond_to do |format|
    format.html { render "#{Rails.root}/public/404.html", status: 404 }
    format.json { render json: { status: 404, message: 'Page Not Found' } }
  end
end
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88