这可能很简单,但是我有一段时间没有弄乱rails了,我不确定自3.2以来情况是否发生了很大变化
所以我有两个模型,报告和收据。每份报告都有很多收据,所以我的模型看起来像:
class Report < ActiveRecord::Base
has_many :receipts, :dependent => :destroy
accepts_nested_attributes_for :receipts, :allow_destroy => true
attr_protected :id
end
class Receipt < ActiveRecord::Base
belongs_to :report
attr_protected :id
validates_presence_of :vendor, :date, :description, :amount, :acctCode
end
我的收据控制器位于控制器文件夹的根目录中,并列出了所有操作(它是由脚手架生成的)
我的路线有:
root :to => "index#index"
resources :reports do
resources :receipts
end
我的 link_to 看起来像这样:
<%= link_to 'New Receipt', new_report_receipt_path, :class=>"btn btn-success" %>
这给了我错误:
No route matches {:action=>"new", :controller=>"receipts"}
我跑了 rake 路线,我得到了以下信息:
report_receipts GET /reports/:report_id/receipts(.:format) receipts#index
POST /reports/:report_id/receipts(.:format) receipts#create
new_report_receipt GET /reports/:report_id/receipts/new(.:format) receipts#new
edit_report_receipt GET /reports/:report_id/receipts/:id/edit(.:format) receipts#edit
report_receipt GET /reports/:report_id/receipts/:id(.:format) receipts#show
PUT /reports/:report_id/receipts/:id(.:format) receipts#update
DELETE /reports/:report_id/receipts/:id(.:format) receipts#destroy
是什么赋予了?