How do I change a rails app so that a controller foo appears as the application root?
In other words, right now all the urls look like host.com/foo/... and I'd like to get rid of the foo and have simply host.com/...
Root Routes Setting the Root Page of the AppThe root webpage is the one that displays for requests that include only the domain/port part of the URL and not the resource path (e.g., http://localhost:3000/). The root webpage is often thought of as the default page for the web app.
root is an instance of Pathname where RAILS_ROOT is a string. You can also Rails. root. join(*%w( app assets images logo.
In routes.rb, add:
map.root :controller => 'foo'
Full details in the API.
In your routes.rb you add a named route like so:
map.home '', :controller => 'foo', :action => 'index'
This will build a route for when the root of web application is requested, it will use the foo controller and call the index action. Make sure you have it at the bottom so it is given the lowest priority.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With