Replies: 1 comment 1 reply
-
Hey! 👋 You will probably want the For example: module SlugGenerator
macro included
after_initialize :generate_slug, on: :create
end
private def generate_slug
self.slug = Nanoid.generate(
size: 21,
alphabet: "1234567890abcdefhjkmnprtxy",
secure: true
)
end
end Let me know if it works! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am new to both Crystal and Marten, but so far they look great! I wonder tho, how do we extract common behavior to a module the way rails do with "concerns."
For my case, I tried to define
SlugGenerator
which then can be included to all models havingslug
field. The module is as follow.However, including them will raise an error:
Error: undefined method 'after_initialize' for SlugGenerator:Module.
Please advise.Beta Was this translation helpful? Give feedback.
All reactions