Should I be using callbacks or should I override attributes?
Posted
by ryeguy
on Stack Overflow
See other posts from Stack Overflow
or by ryeguy
Published on 2010-04-10T05:30:28Z
Indexed on
2010/04/10
5:33 UTC
Read the original article
Hit count: 264
ruby-on-rails
|activerecord
What is the more "rails-like"? If I want to modify a model's property when it's set, should I do this:
def url=(url)
#remove session id
self[:url] = url.split('?s=')[0]
end
or this?
before_save do |record|
#remove session id
record.url = record.url.split('?s=')[0]
end
Is there any benefit for doing it one way or the other? If so, why? If not, which one is generally more common?
© Stack Overflow or respective owner