I have defined a model Item which is subclass of ActiveRecord::Base
It has a association attribute called buyer which is a member
It has a buy method to update the buyer attribute.
# do buy transaction on that item
def buy(people_who_buy, amount)
buyer = people_who_buy
save
....
end
This code cannot update the buyer attribute. The sql generate only do sql selection of member from the database.
But after I add self. before buyer , it works fine.
# do buy transaction on that item
def buy(people_who_buy, amount)
self.buyer = people_who_buy
save
....
end
It looks weird!
Calling
self.write_accessoris required when calling a write_accessor, while inself.read_accessortheselfcan be omitted (and usually is avoided to keep the code a clean as possible).From the community-edited ruby styleguide: