Search code examples
ruby-on-railsruby-on-rails-4routesruby-on-rails-4.2rails-api

ActionController::RoutingError: No route matches [GET] "/"


I have a Rails API which is being accessed by my React client-side. Every time the react application is loaded it makes a get request to the API for the path / and this raises the error:

ActionController::RoutingError: No route matches [GET] "/"

Although this doesn't really affect user interaction on the application but I would still like to remove this.

My API has a normal path of <url>/backend-api/v2.3.3/..

I think this can be fixed by adding a root path on the routes but considering that the initially loaded pages on React are static and don't really need to make an API call, how can I catch this initial GET / and prevent the error from being raised?


Solution

  • add this the routes.rb file under the api scope:

    get '/', to: proc { [200, {}, ['']] }