Routing Error No route matches [GET] /static_pages/home, tutorial
There is no route set for the url '/static_pages/home'
Although root points to static_pages controller with action home, it still responds to the path '/' and not '/static_pages/home'
If you add
match '/static_pages/home', :to =>'static_pages#home'
You will get the expected response for '/static_pages/home'
No route matches [GET] /static_pages/home
It looks like, from your post, that your home.html.erb
template file is in the wrong place. There should be a folder called static_pages
inside app/views
. So inside app/views/static_pages/
is where your home.html.erb
file should be. Your code says it is inside the layouts
folder. Move it and it will work.
So, specifically, either create the folder static_pages
(if it does not exist) or move you home.html.erb file into the app/views/static_pages/
folder.
Just and FYI, if your other views (contact, about, etc) are in the layout
folder move them into static_pages
too. But leave the layout file in there.
Since you are a beginner I'll explain this a little more. When you set your routes you are telling rails where to find the files. So when you write something like get '/help', to: 'static_pages#help
what you telling rails is when the URL /help
is viewed serve up the file help.html.erb
in the static_pages
folder and it knows to look inside the app/views
folder by configuration. If you wanted to keep home.html.erb
where it is, you could just change you routes to root 'layouts#home'
and it should work, but since the view file is not a layout file that would not be the best solution. Hope this helps.
Routing Error :: No route matches [GET] /static_pages/about
Look you do not have any routes "/static_pages/about"
so you got error
Routing Error
No route matches [GET] "/static_pages/about"
As per your routes for about page /about
should be the url
http://localhost:300/about
http://localhost:300/contact
http://localhost:300/help
It will acutally call your static_pages
controller and about
action of that controller
and from url helper of rails routes you get
For About:
about_path
or about_url
should be used
For contact
contact_path
or contact_url
For help
help_path
or help_url
Hartl's Tutorial - Chapter 5.3 Layout Links
Although you have a root mapping, which routes '/' requests to StaticPagesController home action, you have no mapping for the route static_pages/home
. To add it:
match 'static_pages/home', to: 'static_pages#home'
Ruby on Rails Tutorial Chapter 6 RSpec tests are failing, dont know why
You have defined the following routes,
users_new GET /users/new(.:format) users#new
root GET / static_pages#home
signup GET /signup(.:format) users#new
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
In static_pages_spec.rb
, you are accessing routes as visit '/static_pages/home'
, visit '/static_pages/help'
and visit '/static_pages/about'
which would obviously result in No route matches
error as these routes don't exist (match them against the routes listed above).
You need to make following changes in static_pages_spec.rb
:
Error:
No route matches [GET] "/static_pages/home"
Replace
visit '/static_pages/home'
With
either
visit root_path
orvisit '/'
Error:
No route matches [GET] "/static_pages/help"
Replace
visit '/static_pages/help'
With
either
visit help_path
orvisit '/help'
Error:
No route matches [GET] "/static_pages/about"
Replace
visit '/static_pages/about'
With
either
visit about_path
orvisit '/about'
You receive next 2 errors in user_pages_spec.rb
file:
Error:
undefined method 'full_title'
It clearly gives the clue that you are using a method named
full_title
which is not defined anywhere.it { should have_title(full_title('Sign up')) }
## ^
## full_title method here is undefinedError:
expected #has_content?("Sign up") to return true, got false
This error simply means that the following example is failing
it { should have_content('Sign up') }
That means
sign_up
view does not have the text Sign up. Make sure thatsign_up
view has the text Sign up exactly, match the exact case as well.
Rails tutorial - Section 5.2 Routing/Rspec error
Have you removed the public/index.html file and visually verified that you can get to / in your browser, and that the expected template is being rendered? Your spec looks OK otherwise.
Setting up static routes in Rails
All you're missing is as
key:
App::Application.routes.draw.do
root 'static_pages#home'
match '/help', to: 'static_pages#help', via: 'get', as: :help
match '/about', to: 'static_pages#about', via: 'get', as: :about
match '/contact', to: 'static_pages#contact', via: 'get', as: :contact
end
Adding as key will make the routes named and will create required url_helpers.
EDIT:
However, you can do much better:
App::Application.routes.draw.do
root 'static_pages#home'
scope controller: :static_pages do
get :help
get :about
get :contact
end
end
No route matches [GET] /user/1 following Michael Hartls rails tutorial
You should use "/users/1", not "/user/1".
Related Topics
Rails Query Timestamp Between Two Hours
Scraping an Angularjs Application
Could Not Find Gem 'Logstash-Devutils (>= 0) Ruby' in Any of the Gem Sources
Exec Onlyif Registry Value Is Not Present
Issues with Installing Ruby 2.0.0 on MACos Catalina
Why Is My Ruby Git Script Hook Run with the Wrong $Path
Rails - Multi Tenant Application with Customization Framework
Show Markers on Google Maps Dynamically -Rails 3.2
Require Ruby File Without .Rb Extension
Marshal Ruby Hash with Default Proc - Remove the Default Proc
Why #!/Usr/Bin/Env Ruby Doesn't Work in Crontab
When Passing Objects as Parameters, Are They Passed by Reference