undefined local variable or method `root_path' Hartl's Tutorial Chapter 5.3.2

前端 未结 7 1604
长情又很酷
长情又很酷 2021-01-04 05:12

So my first question on Stackoverflow..... =]

My tests in Chapter 5.3.2 of Michael Hartl\'s RoR Tutorial are all failing, when the tutorial says it should be passing

相关标签:
7条回答
  • 2021-01-04 05:47
      root :to => 'static_pages#home' 
      match '/help',    to: 'static_pages#help',    via: 'get'
      match '/about',   to: 'static_pages#about',   via: 'get'
      match '/contact', to: 'static_pages#contact', via: 'get'
    

    works for me

    test results: 9 examples 0 failures

    urls seem to have changed like this now:

    http://localhost:3000/about
    
    0 讨论(0)
  • 2021-01-04 05:54

    Mischa's answer will hopefully fix most of those problems, but your tests may still fail on the root_path issue.

    Have you removed index.html like so: git rm public/index.html

    And don't forget to commit your changes with: git commit -am "Message"

    0 讨论(0)
  • 2021-01-04 05:58

    I am using the same tutorial and ran into the exact same problem! You might've thought it was spork that fixed this but that wasn't it. The reason it worked is because you went ahead and upgraded the Rspec in the next section. It only works with the upgraded rspec - the old rspec was why your tests didn't pass. The site is wrong in that it tells users that the tests will pass before also changing the Rspec

    0 讨论(0)
  • 2021-01-04 05:59

    I have same problem in this chapter, just change in config/routes.rb root to: 'static_pages#home' to root :to => 'static_pages#home' and it's start work. you can also check all routes with rake routes.

    0 讨论(0)
  • 2021-01-04 06:05

    I had a similar issue. My fix was to include the following line in spec_helper.rb

    config.infer_spec_type_from_file_location!
    

    BTW gems are:

    gem 'rails', '4.1.5'
    gem 'rspec-rails', '~> 3.0'
    

    and I also removed all the Guard and Spork stuff.

    0 讨论(0)
  • 2021-01-04 06:08

    I'll put this as an answer because the solution (from @mischa) is buried in the comments under @marflar's answer: try restarting Spork to solve this issue.

    0 讨论(0)
提交回复
热议问题