I’m working on an app where a user inputs their physical address. When
the form is submitted, we are using the USPS webservice to validate
the address and update the fields as necessary.
Code looks as follows:
Address < ActiveRecord::Base
# call USPS service
# if error:
# errors.add_to_base usps_error.message
# self.attributes = usps_address_attributes
the issue is that I get an exception: “can’t modify frozen hash” where
I update the attributes on my Address.
If I move usps_address_lookup into before_save, it works unless I have
USPS validation errors which get completely ignored and the invalid
address gets saved.
TypeError (can’t modify frozen hash):
=' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:309:inwrite_attribute_without_dirty’
write_attribute' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:211:incity=’
send' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2361:inattributes=’
each' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2360:inattributes=’
valid_without_callbacks?' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ callbacks.rb:267:invalid?’
Any ideas? Thanks!