Rails Using REVERSE?
I have the following in my Rails 3 app photo view:
<% for version in @photos.first.versions.reverse %> . .
What's interesting is that on my local machine, it works as hoped by outputting (<%= version.version %>)
5 4 3 2 1
But on Heroku it's backwards
1 2 3 4 5
Is this a Heroky gotcha or maybe reverse is buggy? thanks
I don't know if it's the Ruby version. I've had the same issues and attributed the problem to the fact that Heroku uses PostgreSQL, while in development I use SQLite. I also think it's specifically related to how Postgres orders objects when being called through an association. So the order would be the same for
but different for
What I ended up doing was to use default scopes for some of the models so that they are always ordered in a defined way.
Be careful with default_scope, though. If you try to apply another ordering scope to a model that has a default_scope specifying an order, the the default_scope order will take precedent. I think patches are being worked on for this. But until then, you have to use 'unscoped'
default_scope order('created_at ASC') scope :recent, unscoped.order('created_at DESC')