No route match [GET] "/static_pages/home.html.erb"

I am following Michale Hartl's tutorial and now I am at this stage:

Listing 5.23. Adding a mapping for the root route. config / routes.rb

SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end

      

I copied its exact coding to my config / routes.rb and keep getting the routing error:

Routing error

No [GET] route match "/static_pages/home.html".

-

Not sure what to do at this point so that my home is redirected as an index and to be able to use the root_path to link to "Home".

+3


source to share


4 answers


Remove ../static_pages/..

from the URL entered in the browser.



+4


source


this code is correct

SampleApp :: Application.routes.draw do

root :to => 'static_pages#home'

get '/help' => 'static_pages#help'

get '/about' => 'static_pages#about'

get '/contact' => 'static_pages#contact'

      

end

You don't need to delete the index page, the rspec test in the tutorial is not wrong, this is the updated code with the currently available methods

describe "Home Page" do



it "should have the content 'Sample App'" do

  visit '/'

  page.should have_content('Sample App')

end

      

end

This uses ruby ​​-v ruby ​​2.0.0p47 and rails -v Rails 4.0.3

you may also get a crash if you use before {visit help_path} using the Rails console and checking the path. app.help_path confirms "before {visit help_path] is correct, but if this code is not in spec / rspec_helpers.rb then the test will fail because it cannot find the path

Named routes should work if you put the following in rspec_helper.rb:

Rspec.configure do | config | config.include Rails.application.routes.url_helpers ... end

+1


source


SampleApp::Application.routes.draw do
root :to => 'static_pages#home'
get '/help' => 'static_pages#help'
get '/about' => 'static_pages#about'
get '/contact' => 'static_pages#contact'
end

      

this code is right.

0


source


You need to remove or rename public / index.html and then it will work.

0


source







All Articles