2012年2月16日 星期四

Route & xxx_path & xxx_url 差異

在 Rails 內 會有一些變數 如 xxx_path 或 xxx_url  他們的差異如下:

If you read this code carefully, you can probably figure out what it does;
for example,
you can see that

match '/about', :to => 'pages#about'
matches ’/about’ and routes it to the about action in the Pages controller.
Before, this was more explicit: we used get 'pages/about' to get to the same place, but /about
is more succinct. What isn’t obvious is that match ’/about’ also automatically creates
named routes for use in the controllers and views:
about_path => '/about' about_url => 'http://localhost:3000/about'

【下列文章您可能也有興趣】

沒有留言: