Set default value for Active Record attribute
24 April 2022 (Updated 24 April 2022)
Suppose you want to set a default attribute value for a model so that all new instances of the model have a default attribute. Something like this:
You can do this with the attribute
method:
You can also use a lambda if you want to dynamically generate the value:
Tagged:
Rails
Thanks for your comment . Once it's approved, it will appear here.
Leave a comment