rails 3 tutorial: No route matches [GET] "/"
SO,
Paid for the PDF a few hours ago, followed the instructions carefully but after starting up first_app I see this in localhost:3000:
Routing Error
No route matches [GET] "/"
Haven't touched any code, just started up the server after doing "rails new first_app".
From the command-line:
552 ~/Downloads/rails_projects/first_app>=> Booting WEBrick
=> Rails 3.1.0.rc6 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Sprockets::Environment#static_root is deprecated
[2011-08-20 16:44:40] INFO WEBrick 1.3.1
[2011-08-20 16:44:40] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin10.8.0]
[2011-08-20 16:44:40] INFO WEBrick::HTTPServer#start: pid=97719 port=3000
552 ~/Downloads/rails_projects/first_app>cache: [GET /] miss
Started GET "/" for 127.0.0.1 at 2011-08-20 16:45:06 -0400
ActionController::RoutingError (No route matches [GET] "/"):
Rendered /Users/briano开发者_运维问答/.rvm/gems/ruby-1.9.2-p290@rails3.1/gems/actionpack-3.1.0.rc6
/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within
rescues/layout (7.3ms)
Using rails 3.1 and ruby 1.9.2:
554 ~/Downloads/rails_projects/first_app>rails -v
Rails 3.1.0.rc6
555 ~/Downloads/rails_projects/first_app>ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
Using rvm, created a special gemset, and so on. Any thoughts?
The server is trying to use a caching mechanism (since it's in production mode).
Try running it in development.
This question has a bunch of answers for how to run your app in production (simply, replace their solutions with development).
Have you tried creating a new app and again running rails server command? do get back to me with the answer..
Even i faced the same problem. The possible issue might be you are running the rails server on different app directory. Try to run your rails server from the same path as your app.
I assumed this was from the demo app. The first app has no controllers, so something is broken but you will see this again in the second, demo_app
in the first app, try uncommenting /# root :to => 'welcome#index'
and make sure that the index.html
file is in public.
When you see this in the demo_app
:
You have no route for the main app, or "root" of the app.
If you change the address to http://localhost:3000/users, the index action, which is an
html Get for users will display all your users, which at this point is none.
To fix the problem, you need to add a route to the main url or root (http://localhost:3000).
If you type "rake routes"
, you see that there are routes for users but no route for root.
Open the config/routes.rb
file near the bottom, change the line:
/# root :to => 'welcome#index'
to: root :to => 'users#index'
users#index
is the same as the first route from rake routes.
{:action=>"index", :controller=>"users"}
You have changed the default action to go to users controller and the index action. Rake routes now shows an entry for root.
精彩评论