2

I'm creating mobile api using rails-api and when a user goes to the url for the api, I get the expected "Welcome Aboard" page. What I want to do is remove this and just give the user a 403 page (or 404), if the user attempts to go to the root url with a web browser.

I know that I can create a controller (error_pages), and then match it to a method (no_access) in routes.rb, and then have a page that is rendered by default in the views directory.

root 'error_pages#no_access' # in routes.rb

I'm assuming that there would be an easier way to accomplish this with Rails magic.

Edit:

I found this SO article:

Where is the default "Welcome Aboard" page located in my app?

It states that beginning with Rails 4, the index.html is no longer in the public/ directory, as it is contained in a gem.

Is it possible in the routes.rb file to just point to one of the error pages in the public directory?

I tried the following and it doesn't work:

root 'public/404.html'

I would hate to create a controller to just point to an error page, is there a better rails way?

Community
  • 1
  • 1
5StringRyan
  • 3,604
  • 5
  • 46
  • 69

1 Answers1

0

Simply remove public/index.html. That will result in a 404 (not found) response for requests to the root path.

iltempo
  • 15,718
  • 8
  • 61
  • 72
  • 1
    Since i'm using the rails-api gem, no index.html is created in the public directory. Does this mean that I will just get the "Welcome" page in the dev environment, but once it's pushed to prod (in my case Heroku), it will be a 404? – 5StringRyan Mar 17 '14 at 00:04
  • I just tested it and the file is created in my case. Can you double check it's not there please? – iltempo Mar 17 '14 at 05:55
  • 1
    It looks like starting with Rails 4, the index.html page isn't located in the public directory. I've updated the question. – 5StringRyan Mar 17 '14 at 18:16