Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing error in Ruby on Rails 3

I am new to Ruby on Rails I am getting this error

uninitialized constant WelcomeController

after creating the sample project. I enabled

root :to => 'welcome#index'

in routes.rb.

like image 386
Raj Avatar asked Sep 24 '11 06:09

Raj


2 Answers

When you say

root :to => 'welcome#index'

you're telling Rails to send all requests for / to the index method in WelcomeController. The error message is telling you that you didn't create your WelcomeController class. You should have something like this:

class WelcomeController < ApplicationController
  def index
    # whatever your controller needs to do...
  end
end

in app/controllers/welcome_controller.rb.

like image 74
mu is too short Avatar answered Sep 27 '22 18:09

mu is too short


I'm very very new to Rails and also ran into this error while following along with Rails Tutorial by Michael Hartl. The problem I had was that in the config/routes.rb file, I just uncommented the root :to => "welcome#index":

# just remember to delete public/index.html.
root :to => "welcome#index"

but with the structure of the sample_app was that "welcome#index" should be 'pages#home' instead, since everything was originally set up through the "pages" controller.

root :to => 'pages#home'

It's even right there in the book, but I just overlooked it and spent quite a while afterwards trying to figure out where I went wrong.

like image 26
cchapman Avatar answered Sep 27 '22 17:09

cchapman