【问题标题】:No association found for name Cocoon gem未找到名称 Cocoon gem 的关联
【发布时间】:2016-10-12 02:09:54
【问题描述】:

我正在使用茧宝石。 我有以下错误关联

找不到名称“任务”的关联。已经定义了吗?

在模型维度

class Dimension < ActiveRecord::Base
has_many :task
accepts_nested_attributes_for :tasks, :reject_if => :all_blank, :allow_destroy => true 
end

模型任务

class Task < ActiveRecord::Base
 belongs_to :dimension
end

我已经尝试了一切,审查了其他项目但找不到解决方案

这里是github上的项目链接 https://github.com/renatoVB/testcocoon

【问题讨论】:

    标签: ruby-on-rails cocoon-gem


    【解决方案1】:

    您将Dimension 中的关联定义为单数task。它应该被定义为复数:

    class Dimension < ActiveRecord::Base
      has_many :tasks
      accepts_nested_attributes_for :tasks, :reject_if => :all_blank,   :allow_destroy => true 
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多