I have a model called Contact with an attribute called phone_number.  I have some custom setter methods such as
def prefix=(num)  
  self.phone_number[3..5] = num  
end
When I call @contact.update_attributes({:prefix => '510'}), I don't get any errors and @contact gets changed, but the changes don't make their way to the database.  I've tried using attr_accessible to specifically allow using these setter methods开发者_如何学编程 to no avail.
Is there any way to get update_attributes to work for me?  I'm using Rails 2.3.8.
You have to inform rails that you have changed an attribute as you are performing in place modifications:
def prefix=(num)
  phone_number_will_change!
  self.phone_number[3..5] = num
end 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论