The stack level too deep
error has nothing to do with rails. Any basic Ruby class would do this:
class Post
def tags=(s)
self.tags = s
end
end
> Post.new.tags = "a,b,c"
SystemStackError: stack level too deep
Calling self.tags =
will just re-execute tags=(s)
on the same object, over and over again. In your first example, you're directly setting the attribute via self[:tags] =
, which doesn't re-execute tags=(s)
at all. I would assume an oversimplification of ActiveRecord is that it does something like your first example for all of a model's fields.