Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Routing (root :to => ...)

I know how to set the routes root of my rails app to a controller and an action.

But how to add an id?

/pages/show/1 should be the root.

How do I set this?

like image 338
Joern Akkermann Avatar asked Jun 29 '11 01:06

Joern Akkermann


People also ask

What is root in Ruby on Rails?

In Rails 2.3 Rails. root is an instance of Pathname where RAILS_ROOT is a string.

How do Rails routes?

The Rails router recognizes URLs and dispatches them to a controller's action, or to a Rack application. It can also generate paths and URLs, avoiding the need to hardcode strings in your views.


2 Answers

Had this same problem and this worked for me:

root :to => "pages#show", :id => '1' 
like image 163
Matt D. Avatar answered Sep 24 '22 00:09

Matt D.


As of Rails 4.0, you can declare the root route like this:

root 'controller#action' 
like image 41
Brian Petro Avatar answered Sep 21 '22 00:09

Brian Petro