The documentation on the “create_association” method of the “belongs_to” association reads:
create_association(attributes = {}) Returns a new object of the associated type that has been instantiated with attributes, linked to this object through a foreign key, and that has already been saved (if it passed the validation).*
My expectation from this documentation is that calling “object.create_association” will return the newly created object if both objects save successfully and “false” if either object fails to save (due to failed validations, for example); or throw an error.
My experience, however, is that “create_association” returns the newly created object regardless of whether it saved successfully or not.
How can I catch and handle a situation where “create_association” instantiates and links a new object but is unable to save it?
Rails 2.3.5