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

Answers


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

Photos.all

but different for

Photos.first.versions.all

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')

Need Your Help

Remove-Item returns before file is deleted?

powershell powershell-v2.0 delete-file

In PowerShell, I believe I'm observing that PowerShell is attempting to delete folders before their contents are deleted. The command I'm using is Remove-Item.

How does IIS compare in terms of performance and scalability to weblogic and websphere for enterprise web applications?

java .net iis websphere weblogic

A common argument against using .NET for high volume, transactional enterprise systems is that IIS does not compare to the likes of Weblogic and websphere for java. Is this true? Unfortunately for ...