假设我有一个收据模型,并且我想提供一个控制器操作来打印一个...不放心的方法是:
# receipt_controller.rb
def print
...
end
#routes.rb
resources :receipts do
get :print, :on => :member
end
...宁静的方式是:
# receipt_printings_controller.rb
def create
...
end
#routes.rb
resources :receipts
resources :receipt_printings, :only => :create
我的问题是.....假设我想要具有以下结构:
/app
/controllers
receipts_controller.rb
/receipt
printings_controller.rb
这意味着我的课程看起来像: class Receipt::PrintingsController < ActiveRecord::Base def create ... end end
但我不知道如何在这种情况下正确路由,因为我仍然需要能够做到:
收据_printings_path(123) 获取/receipts/123/printings
我知道如何做到这一点的唯一方法是:
#routes.rb
match "/receipts/:id/printings" => "receipt/printings#create", :as => :receipt_printings
resources :receipts
但是,我想知道是否有更好的方法?