Ruby on Rails + Amoeba Gem:未定义的方法'macro'

时间:2014-08-25 15:52:58

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

我在Rails控制台(使用Ruby 2.1)中尝试了amoeba版本2.0.0。这是我的模特:

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'

我在哪里弄错了?

2 个答案:

答案 0 :(得分:0)

此问题也在GitHub上提出:When using amoeba_dub : undefined method for NilClass

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

答案 1 :(得分:0)

之前

= f.input :chapter, as: :select, collection: Chapter.all

之后

就我而言,我解决了此错误

= f.input :chapter_id, as: :select, collection: Chapter.all