[Rails] before_save gotcha

Pawel Szymczykowski
Fri, 10 Feb 2006 20:46:21 -0000

Is it will known and accepted that before_save triggers should return
true? I didn''t notice this before but now I see it in the
documentation.

Here is what I''m doing in my model:

  def before_save
    if self.has_album?
      self.visible = self.album.visible?
    end
  end

That results in the expected result when album.visible? is true - but
not when it is false. To make it work correctly, I have to explicitly
return true at the end.

  def before_save
    if self.has_album?
      self.visible = self.album.visible?
    end
    true
  end

Is that what I am supposed to do? It feels so wrong and C-like.. is
there a better way?

-Pawel