Routing Error during “Ruby on Rails-Tutorial”

吃可爱长大的小学妹 提交于 2019-12-02 02:48:00

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 .

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

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

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.

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 :)

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

Ronny Mahlangu

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

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.

In

config/routes.rb

uncomment

root :to => 'welcome#index'

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!