ruby-on-rails - 嵌套资源形式上未初始化的常量

我有三个模型,用户、报告和收据。用户有很多举报,举报有很多回执。

现在,我已经设置了一个表单来创建或编辑报告。我需要嵌套另一个表单来创建和编辑收据。我遵循了 Rails 指南(部分 - 构建多模型表单)并编辑了我的模型,并将构建行添加到我的表单 View 中,但我收到了“未初始化常量”错误。

这是我的模型:

class Report < ActiveRecord::Base
  belongs_to :user
    has_many :receipts

  attr_accessible :cash_advance, :company, :description, :end_date, :mileage, :report_name,
  :start_date, :receipts_attributes

    validates_presence_of :company, :description, :end_date, :report_name#, :start_date
    validates_uniqueness_of :report_name

    accepts_nested_attributes_for :receipts, :allow_destroy => :true,
    :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end

class Receipts < ActiveRecord::Base
  belongs_to :report
  attr_accessible :account_code, :amount, :company_card, :date, :description, :lobbying_expense, :vendor
end

和我的表格:

<%# @report.receipts.build %>
<%= form_for([current_user,@report]) do |f| %>
     ...
    <%= f.fields_for ([@report, @report.receipts.build ]) do |receipt| %>
     ...
    <% end %>
<% end %>

我的路线(我不确定是否应该编辑,但在添加收据资源之前我遇到了同样的错误)

resources :users do
    resources :reports do
        resources :receipts
    end
end

我没有编辑报告 Controller ,因为 Rails 指南没有提到它,它只是:

定义新 @report = current_user.reports.new 结束

定义编辑 @report = current_user.reports.find(params[:id]) 结束

我做错了什么?

编辑 - 我更改了我的收据表格,所以 form_for 接受 [@report, @report.receipts.build] 但现在我收到错误:

uninitialized constant Report::Receipt

如何使用此表单?

最佳答案

呃!当我生成模型并给它一个复数名称而不是单数名称时,我搞砸了。这个家伙,就在这里,是个傻瓜。

https://stackoverflow.com/questions/14169094/

相关文章:

regex - Perl 正则表达式匹配字符串不以某物结尾

php - Magento:通过事件以编程方式更新购物车

ruby-on-rails - 即使表中有用户名,也没有用户名字段

visual-c++ - 当类向导被破坏时,将计时器 (WM_TIMER) 处理程序添加到 Visu

exception - gwt、rpc 服务、StatusCodeException 和无可用日志

r - 如何按位置排除向量中的多个元素?

c# - 添加 const 关键字会中断 Path.Combine 调用

jsf - 如何通过 primefaces 中的 beans 在 selectOneRadio/se

r - 生成给定百分位数的分布

r - 使用 theme_wsj {ggthemes} 时如何使 xlab 和 ylab 可见?