Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amoeba_dup on rich_text field raises NoMethodError: undefined method 'macro' on nil:NilClass #110

Open
goulvench opened this issue Jul 27, 2021 · 4 comments

Comments

@goulvench
Copy link

Version 3.2 of Amoeba doesn't support cloning rich_text attributes using the include_association syntax.

The error raised is the same as in issue #79:

# Running…
object_with_rich_text.amoeba_dup
# Raises…
NoMethodError: undefined method `macro` for nil:NilClass
from '/usr/local/bundle/gems/amoeba-3.2.0/lib/amoeba/cloner.rb:110' in `follow_association`

The customize syntax allows working around that limitation though, here is what works for me:

class MyClass
  has_rich_text :content

  amoeba do
    customize ->(original, cloned_object) do
      cloned_object.content = original.content
    end
  end
end

Under-the-hood, rich text associations are defined using has_one :"rich_text_#{name}", it would be nice if Amoeba was able to clone action_text natively, let me know if a PR would be welcome.

@goulvench goulvench changed the title amoeba_dup on rich_text field raises `NoMethodError: undefined method 'macro' on nil:NilClass amoeba_dup on rich_text field raises NoMethodError: undefined method 'macro' on nil:NilClass Jul 27, 2021
@jrmhaig
Copy link
Collaborator

jrmhaig commented Jul 28, 2021

@goulvench Thank you for raising this. If you want to have a go at a PR that would be very much appreciated. Although I've become a maintainer I am a long way from being an expert (yet) but I am hoping to get this gem more actively maintained.

I have added the label 'enhancement'. Do you think this is appropriate, or would you consider it a bug? It should at least fail silently, which would suggest it is a bug.

@goulvench
Copy link
Author

Hi, I would qualify this as a bug since rich_text are has_one associations and they are supposed to work out of the box. Plus ActionText has been around for quite a while now.

I'll see if I can work something out but I also have tons of work at the moment so I may not find time before a while. I'll let you know.

Apart from that, Amoeba works like a charm and I was able to implement a requirement in just the time it takes to read the docs, so thanks for this gem!

@primaulia
Copy link

primaulia commented Jul 18, 2022

Thanks for pointing this out @goulvench, it seems that this issue is also occurring when working with active_storage.

I had to do this as a work-around

class MyClass
  has_one_attached :picture

  amoeba do
    customize(lambda { |original, new_object|
      new_object.picture.attach(original.picture.blob)
    })
  end
end

will look into the codebase and see if this can be rectified

@ekampp
Copy link

ekampp commented Feb 14, 2024

Also, when copying a (source) record that has a rich text field, the new (copy) record has an ActionText::RichText, but it does not persist the ActionText::RichText association.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants