i am following a rails tutorial from this link:
http://ruby.railstutorial.org/chapters/filling-in-the-layout#code:static_page_routes
in the /config/routes.rb file, i have
SampleApp::Application.routes.draw do
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => 'pages#home'
end
when i run the site, it gives me an error: no route exist pages/home. i search around the forum and ppl suggest putting match '/pages/home' => 'pages#home'
which i did:
SampleApp::Application.routes.draw do
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/pages/home' => 'pages#home'
root :to => 'pages#home'
end
everything works. but now, my question is, what is the difference between
1. match '/something', :to => 'pages#something'
2. match '/something' => 'pages#something'
3. root :to => 'pages#home'
basically, the code i just put. shouldn't the root takes take of the main home page and i wont' need match pages/home => pages#home?
so confusing,
Thanks!
EDIT1: I'm not getting the answers I want and so I assume my question is wrong. I'll break it down into 2 parts:
What is the difference between:
match '/pages/home' => 'pages#home'
AND
root :to => 'pages#home'
some say that root takes it to your root page which i can understand but as i explained above, if i just have root to: the pages/home shows a routing error. pages/home should be the same as the root page, correct?
what is the difference between:
match '/contact', :to => 'pages#contact'
AND
match '/pages/home' => 'pages#home
syntactically, the first line has the :to => and the 2nd line does not. is the to: needed? what does it do?
thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…