I have the following model
class Job < ActiveRecord::Base
attr_accessor :incentive
end
I want to be able to store a temporary column in my model via attr_accessor.
I want to be able to do something like this
job = Job.last
job.incentive = {id: 1}
and i expect if i do job.incentive
, it should return {id: 1}
I also tried doing this as well
def incentive =(val)
@incentive = val
end
def incentive
@incentive
end
But that also didn't work. How can i be able to store temporary column values in rails 4
You script is fine, you'll find the below script working perfectly in your rails console:
If you restart or refresh your console (or webpage) this information is gone, since it is only set in memory and not stored to the database.