I do a first_or_create statement, followed by a update_attributes:
hangout = Hangout.where(tour: tour, guide: current_user).first_or_create
hangout.update_attributes(priority: current_user.priority)
If the record already existed, it updates the priority. If it doesn't exist previously, there is no update. Why?
Thanks!
update_attributes(akaupdate) returns a boolean indicating if there was an error, if you do not check it - use bang-versionupdate!so that exception will not be ignored.Most probably record does not get created due to validation. Also when you're updating new record just after create - better use
first_or_create(priority: current_user.priority)orfirst_or_initialize(with subsequent update) to spare extra DB write.