Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Array.count available in dev mode but not production?

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

like image 738
cakeforcerberus Avatar asked Aug 27 '09 15:08

cakeforcerberus


1 Answers

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.

like image 200
Samir Talwar Avatar answered Oct 19 '22 11:10

Samir Talwar