开发者

How to properly define the routes of my rails application?

I am following this tutorial and at first the config/routes.rb file contained these:

SampleApp::Application.routes.draw do

  get "pages/home"

  get "pages/contact"

  get "pages/about"

  get "pages/help" 

...

now in the tutorial it states that it contains these

SampleApp::Application.routes.draw do
  match '/contact'开发者_如何学Python, :to => 'pages#contact'
  match '/about',   :to => 'pages#about'
  match '/help',    :to => 'pages#help'
  .
  .
  .
end

I used the above, but it doesn't seem to work. what is the correct one?


Both match and get are valid route definitions. I would recommand using get though.

get "/home" => "pages#home"

This will route the uri /home to the controller Pages, with the action home.
But only for the GET requests.

You could do, for example :

post "/home" => "pages#create_home"

If you use match :

match "/home" => "pages#home"

This will route the uri /home to the controller Pages, with the action home. But for all HTTP verbs, not only GET.

Take a look at the rails guides : routing applications


Both are correct and valid. Read through this guide for more info. Maybe, you're trying to access '/pages/contact' which doesn't work any more and you have to access that page by just '/contact'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜