Can I remove the default root in a Rails application without creating a new one?

By default, rails will render 404 default page(not welcome page) in production.


If you want to render a 404 response, there are two approaches that I can think of.

Firstly, you could route to Rack, and return a simple 404 response:

# config/routes.rb
root to: proc { [404, {}, ["Not found."]] }

Secondly, you could take the obvious route and point root to a controller action that returns 404:

# config/routes.rb
root to: "application#not_found"

# app/controllers/application_controller.rb
def not_found
  render plain: "Not found.", status: 404
end

The third option is, of course, to route to a non-existing action, but I don't think this is a good idea, since the intention is obscured, and could easily be taken for a mistake.


If you remove it, you will see the default greeting from Rails, which includes some technical information about your environment. Unlikely this is the behavior you need.

I solved it this way:

Rails.application.routes.draw do
  namespace :admin do
    ...
  end

  # To prevent users from seeing the default welcome message "Welcome aboard" from Rails
  root to: redirect('admin/sign_in')
end