user1934428
user1934428

Reputation: 22237

Ruby on Rails + Amoeba Gem: undefined method 'macro'

I tried amoeba version 2.0.0 in the Rails console (with Ruby 2.1). This is my model:

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

Now in the Rails console I try

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

This raises the exception

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'

Where did I make a mistake?

Upvotes: 1

Views: 1172

Answers (1)

Andrew Grimm
Andrew Grimm

Reputation: 81540

This question was also asked on GitHub: When using amoeba_dub : undefined method for NilClass

It was caused by include_field being used on something that wasn't an association. Don't do that! To avoid ambiguity in the future, include_field was renamed to include_association.

Upvotes: 0

Related Questions