Rename write_attribute to write_state_attribute

This avoids a conflict with ActiveRecord that leads to a "stack level too deep" error whenever initializing a new record.