routes.rb error

I'm new to ruby and trying to make a welcome page. I changed routes.rb to: map.connect '', :controller => "welcome"

and deleted index.html, but still I get the error:

NameError in WelcomeController#index

uninitialized constant WelcomeController

RAILS_ROOT: /home/hkhan/digg Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:266:in `load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:453:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:465:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/inflector.rb:257:in `constantize' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/core_ext/string/inflections.rb:148:in `constantize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/routing.rb:1426:in `recognize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:170:in `handle_request' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:115:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:126:in `dispatch_cgi' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:9:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 112:in `handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 78:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 62:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ webrick.rb:66 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:342:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb: 39 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3

/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:266:in `load_missing_constant' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:453:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:465:in `const_missing' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/inflector.rb:257:in `constantize' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/core_ext/string/inflections.rb:148:in `constantize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/routing.rb:1426:in `recognize' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:170:in `handle_request' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:115:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:126:in `dispatch_cgi' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:9:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 112:in `handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 78:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb: 62:in `dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ webrick.rb:66 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:342:in `new_constants_in' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/ active_support/dependencies.rb:496:in `require' /usr/local/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb: 39 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3

Request

Parameters:

None

Show session dump

My routes.rb looks like this:

map.connect ' ', :controller => "main", :action => "welcome"

Notice that following connect there are two apostrophes, not a quote. Also, the controller is "main" and the action is "welcome".

Within the main controller, the following resides:

def welcome     @categories = Category.find(:all)   end

Look into the views folder within welcome.rhtml, and you'd find this:

<% @categories.each do |category| %>

<p><%= link_to "#{category.name}",         :controller => "category",             :action => "show",             :id => category.id %></p>     <% end %>

The controller sets up the array that the view peers into and uses to produce the selection of links.

Hope this helps.

Please make sure welcome_controller.rb exists in your controllers directory and then your views contain a welcome directory with an rhtml file with the name of your action. In this case it would be index.rhtml

Love AJAX wrote:

Please make sure welcome_controller.rb exists in your controllers directory and then your views contain a welcome directory with an rhtml file with the name of your action. In this case it would be index.rhtml

That worked great...thanks