Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on rails application root

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/...

like image 740
Bee Avatar asked Jan 23 '09 05:01

Bee


People also ask

What is root in Ruby on Rails?

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.

What is the root of a Rails project?

root is an instance of Pathname where RAILS_ROOT is a string. You can also Rails. root. join(*%w( app assets images logo.


2 Answers

In routes.rb, add:

map.root :controller => 'foo'

Full details in the API.

like image 193
Abie Avatar answered Sep 16 '22 13:09

Abie


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.

like image 37
Dale Ragan Avatar answered Sep 19 '22 13:09

Dale Ragan