I'm trying to setup an attribute that isn't saved to the database but I can't work out how to change it and read the new value.
class User < ApplicationRecord
attribute :online, :boolean, default: false
end
in Rails Console:
User.first.online = true
=> true
User.first.online
=> false
I'm running Ruby-on-rails 5.2.4.1 and ruby 2.4.1 https://api.rubyonrails.org/v5.2.4.1/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
attribute
method and you know that these kinds of attributes are not saved into the database. But at the same time, you expect that the attribute should be persistent? Why do not you just save it into the database? How do you think the attribute should be persistent when it is not stored in the DB? – spickermann