How can I override the attribute assignment in an active record object?
Posted
by ryeguy
on Stack Overflow
See other posts from Stack Overflow
or by ryeguy
Published on 2010-03-27T05:53:37Z
Indexed on
2010/03/27
6:03 UTC
Read the original article
Hit count: 266
ruby-on-rails
|activerecord
I know you can do this with virtual attributes, but what if the column actually exists?
For example, my model has a raw_topic
column. When raw_topic
is set, I want artist
and song_title
to be set based off of raw_topic
's contents. Ideally, I'd like to override the raw_topic=
method, but rails doesn't seem to like that.
What's the proper way of doing this? Is a callback the only way?
© Stack Overflow or respective owner