oRbb
oRbb

Reputation: 11

Routing Error during "Ruby on Rails-Tutorial"

It seems like some people here had this problem but I couldn't find any solution in another topic.

I am doing Chapter 3 of the Ruby on Rails-Tutorial, working on the static pages. When I want to open them on the localhost it gives me a "Routing Error" in the Browser.

My Ruby is currently on version 1.9.3. My Rails is currently on version 3.2.

I have tried:

Also there are no bugs in the HTML code of the single static page. And I can't find any more help in the tutorial, neither in other questions here on StackOverflow.


Edit:

This is the actual error message from the browser:

Routing Error

No route matches [GET] "/static_pages/home" Try running rake routes for more information on available routes.

if I go to http://localhost:3000/static_pages/home, to one of three static pages I have.

This is routes.rb:

SampleApp::Application.routes.draw do
  
get "static_pages/home"

get "static_pages/help"

get "static_pages/about"

end

Also, I tried "rake routes" in the terminal, too. This is the result:

home_static_pages GET    /static_pages/home(.:format)  static_pages#home
 help_static_pages GET    /static_pages/help(.:format)  static_pages#help
about_static_pages GET    /static_pages/about(.:format) static_pages#about
      static_pages POST   /static_pages(.:format)       static_pages#create
  new_static_pages GET    /static_pages/new(.:format)   static_pages#new
 edit_static_pages GET    /static_pages/edit(.:format)  static_pages#edit
                   GET    /static_pages(.:format)       static_pages#show
                   PUT    /static_pages(.:format)       static_pages#update
                   DELETE /static_pages(.:format)       static_pages#destroy

And this is the error message the server is giving me:

Started GET "/static_pages/home.html" for 127.0.0.1 at 2012-04-03 13:23:54 +0200

ActionController::RoutingError (No route matches [GET] "/static_pages/home.html"):
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

Upvotes: 1

Views: 13602

Answers (9)

Mronzer
Mronzer

Reputation: 439

Once you change the format of your mapping from get to match you will not need static_pages anymore, just go straight to localhost:3000/pagename e.g localhost:3000/about

Upvotes: 0

aug2uag
aug2uag

Reputation: 3445

check your http:// address, specifically if you are on localhost:3000/path or localhost:3000/path1/path2, etc

Upvotes: 0

Vladimir Brasil
Vladimir Brasil

Reputation: 693

If you are using Spork you must re-run Spork so your tests will consider the changes in config files like routes.rb, that are pre-loaded with Spork, so are not automatically updated.

  1. Stop Spork (Ctrl + C)
  2. Run Spork again (bundle exec spork)

Source: this is the source of this information "after changing a file included in the prefork loading (such as routes.rb), you will have to restart the Spork server to load the new Rails environment. If your tests are failing when you think they should be passing, quit the Spork server with Control-C and restart it

Upvotes: 3

The HCD
The HCD

Reputation: 510

In

config/routes.rb

uncomment

root :to => 'welcome#index'

Upvotes: -1

Esperanto
Esperanto

Reputation: 1

From Ruby 2 to Ruby 3 there are some differences, but still the documentation for 3 is not easy to be found. There should be a tutorial only for that: practical differences between rails 2 and 3. The guide provided by downloading Ruby on rails is "The book of ruby" but it's not good anymore. It should at least contain an advice at the beginning of chapter 19.

Upvotes: -1

Philip Mossop
Philip Mossop

Reputation: 1

If you check the routes.rb in config you'll probably find that the there is a 'e' missing from /home. Add that and you are golden. Or green. Or whatever :)

Upvotes: 0

Chris Fletcher
Chris Fletcher

Reputation: 2387

I had a few problems working through the Rails Tutorial, and it helped to be able to consult the author's GitHub repo: https://github.com/railstutorial

Find the file you're working on and compare it line by line. Or just cut and paste the full file and see if it will run, then track down your error.

Upvotes: 0

Vik
Vik

Reputation: 5961

Try this :

match "/static_pages/home" => "static_pages#home", :via => :get
match "/static_pages/help" => "static_pages#help", :via => :get
match "/static_pages/about" => "static_pages#about", :via => :get

Add into routes , restart the server and refresh browser .

Upvotes: 3

Siwei
Siwei

Reputation: 21549

your routes.rb file has problems, use either RESTful style:

resource :static_pages do 
  collection do 
    get :home
    get :help
    get :about
  end 
end

or the non RESTful style:

match "static_pages/home", :controller => "static_pages", :action => "home"
match "static_pages/help", :controller => "static_pages", :action => "help"
match "static_pages/about", :controller => "static_pages", :action => "about"

for more details please refer to official guide: http://guides.rubyonrails.org/routing.html

Upvotes: 0

Related Questions