views:

202

answers:

2

For a recent project, I had a couple views with code like this:

<% if @users.count == 0 %>

This worked perfectly in development mode... I rolled it out to prod mode and it exploded, saying that count was not a valid method of Array. I changed every instance to use Array#length instead and it seems to be working.

1) What is the reason for this difference in behavior?

2) Are there any other exciting differences between dev and prod modes that I should watch out for?

MORAL: Make sure your production hosting environment uses the same version of Ruby as your local development environment. :)

Thank you

Tom

+8  A: 

The count method is only available in Ruby 1.9 and up. I recommend you use the same version of Ruby as your server to avoid problems like this - a lot has changed in 1.9.

Samir Talwar
Interesting. I didn't even consider the fact that my dev environment was running a different version of ruby than my hosting environment. I feel silly now. Can I delete this question? ;) +1
cakeforcerberus
I don't recommend it. Someone else might have the same problem. I only knew the answer because I had a similar issue a few months back.
Samir Talwar
I was pretty sure this was introduced in 1.8, somewhere... this bit me, at one point, and I'm not working with 1.9.
Bill D
Yes: 1.8.7 vs 1.8.6 was what caused me the problem.
Bill D
Ah, I was a little off. It seems 1.8.7 backported a bunch of stuff, including `count`.
Samir Talwar
A: 

omg, bluehost has Ruby 1.8.6 and now, half of my application is not working. Mostly exactly because of this problem, with count.

Yeah, that is exactly what happened to me. Developed locally and uploaded to bluehost only to discover this discrepancy between the version. Painful.
cakeforcerberus