【问题标题】:Ruby on Rails + Amoeba Gem: undefined method 'macro'Ruby on Rails + Amoeba Gem:未定义的方法“宏”
【发布时间】:2014-08-25 15:52:58
【问题描述】:

我在 Rails 控制台中尝试了变形虫 2.0.0 版(使用 Ruby 2.1)。这是我的模型:

class Dict < ActiveRecord::Base
  belongs_to :user
  has_many :cards, dependent: :destroy
  has_many :idioms, through: :cards
end
class Card < ActiveRecord::Base
  belongs_to :dict
  has_many :idioms, dependent: :destroy
  amoeba do
    exclude_field :dict_id
  end
end
class Idiom < ActiveRecord::Base
  belongs_to :card
  amoeba do
    include_field :repres
    include_field :card_id
    include_field :kind
    include_field :note
  end
end

现在我在 Rails 控制台中尝试

c=Card.find_by_id(19) # yields a Card object
c.amoeba_dup

这会引发异常

NoMethodError: undefined method macro' for nil:NilClass
from .../amoeba-2.0.0/lib/amoeba.rb:412:in amo_process_association'
from .../amoeba-2.0.0/lib/amoeba.rb:381:in block in amoeba_dup'
from .../amoeba-2.0.0/lib/amoeba.rb:379:in each'
from ..../amoeba-2.0.0/lib/amoeba.rb:379:in amoeba_dup'
from .../amoeba-2.0.0/lib/amoeba.rb:457:in block in amo_process_association'

我在哪里做错了?

【问题讨论】:

    标签: ruby-on-rails-4 clone amoeba-gem


    【解决方案1】:

    这个问题也在 GitHub 上被问到:When using amoeba_dub : undefined method for NilClass

    这是由于 include_field 被用于非关联的事物所引起的。不要那样做!为避免日后出现歧义,include_field 已重命名为 include_association

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 2016-12-15
      • 2019-10-31
      相关资源
      最近更新 更多