views:

27

answers:

3

Hi,

I am just starting with rails and I have a very simple case. I have a "home" controller. There is one action 'index' defined in this controller. When I go to ~/home I get an error msg saying:

uninitialized constant HomesController (I noticed the singular/plural thing).

That's the first thing I don't get (I thought it would automatically go to ~/home/index).

Second thing, if I go to ~/home/edit (note that this action doesn't exist yet), I get also: uninitialized constant HomesController But if I go to ~/home/show (show doesn't exist as well) I get a different error message:

No route matches "/home/show"

How can I get 2 differents errors for the same reason (an inexistant action). And What's the deal with this constant?

Thank you

Edit I'm running rails 3.0

Here is my routes.rb file

Topnotch::Application.routes.draw do
  resources :subscriptions
  resource :home

  get "home/index"

  get "subscriptions/index"

  root :to => "home#index"
end
+1  A: 
  1. You must add the resource "home" to the route.rb.
  2. The controllers are considered to be plural.
  3. If you are new to rails, I suggest you to start using generators - just open a terminal in the project's folder and type in "script/generate scaffold home" (in rails3 it would be "rails g home")
Lucho
I used the generator to generate a controller (I didn't need a model for my home controller!). Also, I already have a resource for home in route.rb). Am I obliged to choose a plural name for the controller?
Amokrane
+1  A: 

Changes the root route as below:-

root :to => "homes#index".

You must use the plural form in the routes.

Saran
+1  A: 

Turns out, the routes were correct I was just not using them correctly ! rake routes helped.

Amokrane