On 10-10-19 05:20 PM, Murph2m wrote:
Hi All,

I am following a Ruby on rails tutorial and everything is working but
I am struggling a bit to follow what is happening and why:

I have created the following routes.db and I just want some help
understanding what it is doing?

SampleApp::Application.routes.draw do
   get "pages/home"
   get "pages/contact"
   get "pages/about"
   get "pages/help"

   match '/contact', :to =>  'pages#contact'
   match '/about',   :to =>  'pages#about'
   match '/help',    :to =>  'pages#help'

   root :to =>  'pages#home'
end

I am in the process of reading http://guides.rubyonrails.org/routing.html
but it is a learning curve!

Is it saying to match '/contact' with 'pages/contact' and to get
'pages/contact'?  If so what is the # for in 'pages#contact'?

Any help understanding really appreciated!

Thanks

Matt


match '/contact', :to =>  'pages#contact'

reads, match path '/contact' and load controller Pages and execute action 'contact'

however you can remove the comma and also ':to =>' to define the route as:

        match '/contact' => 'pages#contact'

if you run 'rake routes' you will see:

contact  /contact(.:format) {:controller=>"pages", :action=>"contact"}

this tells you that the format "pages#contact" is in the form:

        controller#action


--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to