Last active
April 5, 2019 12:23
-
-
Save ccyrille/ba8c4e2e50c7e23f3873c9199ab7f38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
... | |
# << REMOVE ON NEXT RELEASE | |
def new_column | |
read_attribute(:new_column) if has_attribute?(:new_column) | |
end | |
def new_column=(value) | |
write_attribute(:new_column, value) if has_attribute?(:new_column) | |
end | |
# >> REMOVE ON NEXT RELEASE | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could refactor this code quite a bit:
This will also allow you to use the usual rails method when the migration is already done, quite better than using
read_attribute
/write_attribute
, which may have a different effect.However, this would change the behavior written here. It would save the attribute per instance instead of ignoring when using
User#new_column=
. For instance:To keep the first behavior, you could write: