2013年5月7日火曜日

[Rails4] named route with helper in routes.rb

http://ruby.railstutorial.org/chapters/filling-in-the-layout?version=4.0#sec-rails_routes

In rails4, the notation of routes.rb has been changed:

Rails3:

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

Rails4:

SampleApp::Application.routes.draw do
  root to: 'static_pages#home'
  get 'help' => "static_pages", as: 'help'
  get 'about' => "static_pages", as: 'about'
  get 'contact' => "static_pages", as: 'contact'

Enjoy!

0 件のコメント:

コメントを投稿