Topic: Problem when routing index

Hi,
I'm trying to define the root of my project ( index ). It means that when I execute http://localhost:3000/ I would like to run demo->index method.
To do this I have edited routes.rb like this:

map.root :controller => 'demo', :action => 'index'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

I restart WEBrick, go to http://localhost:3000/ and I get:
"Routing Error
No route matches "/" with {:method=>:get}"

I have deleted public/index.html
I'm using rails 2.3.5 under ubuntu

Thanks in advance

Last edited by ratamaster (2010-11-07 19:55:50)

Re: Problem when routing index

Strange, i'm using rails 2.3.4 and just tried commenting all my routes except the ones you list and it's fine.  What does

rake routes

give you?

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: Problem when routing index

Max Williams wrote:

Strange, i'm using rails 2.3.4 and just tried commenting all my routes except the ones you list and it's fine.  What does

rake routes

give you?

Processing ApplicationController#index (for 127.0.0.1 at 2010-11-08 19:34:21) [GET]

ActionController::RoutingError (No route matches "/" with {:method=>:get}):
  /usr/lib/ruby/1.8/action_controller/routing/recognition_optimisation.rb:66:in `recognize_path'
  /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:441:in `recognize'
  /usr/lib/ruby/1.8/action_controller/routing/route_set.rb:436:in `call'
  /usr/lib/ruby/1.8/action_controller/dispatcher.rb:87:in `dispatch'
  /usr/lib/ruby/1.8/action_controller/dispatcher.rb:121:in `_call'
  /usr/lib/ruby/1.8/action_controller/dispatcher.rb:130:in `build_middleware_stack'
  /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call'
  /usr/lib/ruby/1.8/active_record/query_cache.rb:29:in `call'
  /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache'
  /usr/lib/ruby/1.8/active_record/query_cache.rb:9:in `cache'
  /usr/lib/ruby/1.8/active_record/query_cache.rb:28:in `call'
  /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call'
  /usr/lib/ruby/1.8/action_controller/string_coercion.rb:25:in `call'
  /usr/lib/ruby/1.8/rack/head.rb:9:in `call'
  /usr/lib/ruby/1.8/rack/methodoverride.rb:24:in `call'
  /usr/lib/ruby/1.8/action_controller/params_parser.rb:15:in `call'
  /usr/lib/ruby/1.8/action_controller/session/cookie_store.rb:93:in `call'
  /usr/lib/ruby/1.8/action_controller/failsafe.rb:26:in `call'
  /usr/lib/ruby/1.8/rack/lock.rb:11:in `call'
  /usr/lib/ruby/1.8/rack/lock.rb:11:in `synchronize'
  /usr/lib/ruby/1.8/rack/lock.rb:11:in `call'
  /usr/lib/ruby/1.8/action_controller/dispatcher.rb:114:in `call'
  /usr/lib/ruby/1.8/action_controller/reloader.rb:34:in `run'
  /usr/lib/ruby/1.8/action_controller/dispatcher.rb:108:in `call'
  /usr/lib/ruby/1.8/rack/urlmap.rb:47:in `call'
  /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `each'
  /usr/lib/ruby/1.8/rack/urlmap.rb:41:in `call'
  /usr/lib/ruby/1.8/rack/content_length.rb:13:in `call'
  /usr/lib/ruby/1.8/rack/handler/webrick.rb:48:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
  /usr/lib/ruby/1.8/rack/handler/webrick.rb:14:in `run'

Rendering rescues/layout (not_found)

Then I have changed the code from routes.rb to ( I have read that defining the root at the bootom is right ):

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
root :to => 'demo#index'

... but I get the same result.

I should add that I'm running my code under var/www, on an apache server, and I have tried to config apache with rails without success, I get "Ruby on Rails application could not be started......Error message: No such file or directory - config/environment.rb"

Maybe some apache config is disturbing WEBrick ?

This is my demo controller:

class DemoController < ApplicationController
  def index
  end

end

Re: Problem when routing index

Nevermind !
I had a system permission problem, that was the reason ! Sorry, I'm new in rails and ubuntu.

Re: Problem when routing index

Apache could be interfering with webrick if you have a rewrite rule in apache, eg to redirect "/" to a different url, and that different url is what breaks rails.

BTW, when i asked what 'rake routes' gives you, i meant that you should go to your app's root folder in the terminal and type 'rake routes' (no quotes) and post up the output.  The thing you posted up is generally referred to as the 'stack trace', which is the bug reporter working it's way back down the stack of things in memory when the error occurred.

Last edited by Max Williams (2010-11-09 06:13:00)

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: Problem when routing index

Thanks for your help

Re: Problem when routing index

What permission error did you have!?
I have exactly the same problem...

Ubuntu 10.10
Using xampp (lampp)