I have a strange issue setting data inside an active record..
When I attempt to set the data inside a method, it doesn’t seem to affect anything.
Here’s my class
class Option < ActiveRecord::Base
serialize :returns_policy_refunds, Array
def reloadRefundOptions!
@returns_policy_refunds = WebSite.get_refund_options #options array
end
end
Simple as’ class eh?
To test serialization I’m just spitting out the data on a screen..
-@options.each do |option|
- option.returns_policy_refunds = ["wtf"] #just to reset things
<b>BLOCK 1</b>
= option.reloadRefundOptions!
= option.returns_policy_refunds
<br>
<b>BLOCK 2</b>
= option.returns_policy_refunds = WebSite.get_refund_options
= option.returns_policy_refunds
Now.. I’d expect to see the same in BLOCK1 as in BLOCK2..
The method sets the return policy..
What I actually see in the first option.returns_policy_refunds is [“wtf”]
What am I missing? I must be doing something wrong, but I have no idea what.
Any thoughts?
Leave out the
@in your attribute assignment:Haven’t tried it yet but I would say that
option.returns_policy_refundsgets the data from the attributes hash defined by ActiveRecord. If you assign a class variable using@it’s just defined there and may only be accessed with an attribute reader or a direct send.