Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Last active January 29, 2019 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbuehlmann/0c36c0ac0e81de8b20f54879d3e42227 to your computer and use it in GitHub Desktop.
Save tbuehlmann/0c36c0ac0e81de8b20f54879d3e42227 to your computer and use it in GitHub Desktop.
class SomeModel < ApplicationRecord
after_initialize do
if new_record?
{some_attribute: 'default value'}.each do |attribute, value|
public_send("#{attribute}=", value) unless public_send(attribute)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment