我正在阅读 Rails 3 In Action。本书构建了一个 Projects whichhas_many :tickets
类和一个 Tickets which 类belongs_to :project
。routes.rb 文件如下所示:
resources :projects do
resources :tickets
end
现在,用于创建票证的表单采用如下数组:
<%= form_for [@project, @ticket] do |f| %>
在票 show.html.erb 页面上有如下链接:
<%= link_to "Edit Ticket", [:edit, @project, @ticket] %>
<%= link_to "Delete Ticket", [@project, @ticket], :method => :delete,
:confirm => "Are you sure you want to delete this ticket?" %>
现在我很困惑为什么需要将两个对象的数组传递给 form_for() 和 link_to()。另外,为什么“编辑票证”需要和 :edit 符号,而“删除票证”不需要 :destroy 符号。
谢谢,迈克