【发布时间】:2012-02-22 14:53:31
【问题描述】:
我是学习 Ruby 和 Rails 的初学者。
我正在阅读 Rails 3.2.1 指南的以下部分:
http://guides.rubyonrails.org/routing.html#paths-and-urls
上面写着:
Creating a resourceful route will also expose a number of helpers to the controllers
in your application. In the case of resources :photos:
photos_path returns /photos
new_photo_path returns /photos/new
edit_photo_path(:id) returns /photos/:id/edit (for instance, edit_photo_path(10) returns /photos/10/edit)
photo_path(:id) returns /photos/:id (for instance, photo_path(10) returns /photos/10)
我很想知道这些助手是如何以及何时在请求的生命周期中创建的,即 new_photo_path、edit_photo_path 等,以及在源代码中我可以在哪里找到执行相同操作的代码。
我正在浏览以下文件 /gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb 中的代码,我猜这个文件中的代码正在创建上面帮手。如果我错了,请纠正我。
谢谢,
吉格尼什
【问题讨论】: