10

I'm having a very weird bug. In my code I have <%= time_ago_in_words(game.created_at) %>

It's works locally and on my staging server but NOT on my production server:

Example: http://hockey-community.com/games/show/45

I get "in {{count}} days."

Weirdly, if the number returned is 1, it works. (ex: 1 hour ago or 1 day ago).

Any idea would be very helpful. Thks

Alextoul
  • 839
  • 3
  • 9
  • 19
  • What version of Rails? Have you checked that the `created_at` value is sane? – Matchu Dec 02 '10 at 00:50
  • 2.3.8, I test my local with the same database so created_at have same format. I wondering if it's not a heroku issue. Thks – Alextoul Dec 02 '10 at 07:38
  • 1
    I have the same problem. Yesterday everything was working fine, but today I reinstalled my Windows, as well as Ruby with Rails and all the gems... Then I pulled my app's db from Heroku and... I see "{{count}}"s everywhere :) – sNiCKY Dec 02 '10 at 16:52

4 Answers4

13

Rails was using some deprecated syntax in the helper which then got dropped in the latest Ruby version. If you are using something like Heroku, try telling your production instance to use Rails 2.3.9. Otherwise you can also try downgrading Ruby.

See the changelog: http://weblog.rubyonrails.org/2010/9/4/ruby-on-rails-2-3-9-released

Changes i18n named-interpolation syntax from the deprecated Hello {{name}} to the 1.9-native Hello %{name}.

This looks like it will fix your problem.

smudge
  • 801
  • 1
  • 6
  • 21
2

It sounds to me like you don't have the same version of Ruby in Production as you do in Development. Personally I still have Ruby 1.8.7 in my Development and in the Console, I constantly get the following message when I use time_ago_in_words:

The {{key}} interpolation syntax in I18n messages is deprecated. Please use %{key} instead.

Now this message about deprecated does not come from Rails, it comes from Ruby. And since time_ago_in_words is a Rails helper, it seems like this feature in Rails is not compatible with the later versions of Ruby where this has been removed.

So unless you manually want to monkey patch the actual helper in some way (I wouldn't recommend it) you can either upgrade Rails or downgrade Ruby so that they are compatible.

DanneManne
  • 21,107
  • 5
  • 57
  • 58
2

I had the same problem after recently adding the i18n gem. I'm on a project where upgrading Rails isn't currently a viable option. After reading through this post and nearly ripping out time_ago_in_words, I found several similar posts.

Copying http://gist.github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml into my config/locales/en.yml as suggested here: time_ago_in_words issue worked great. Just be aware that yml is very finicky about white space.

Community
  • 1
  • 1
davidkovsky
  • 1,147
  • 8
  • 10
0

This is happening to me to.

I tried inserting the "datetime:" section from

https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/en-US.yml

into my own en.yml, hoping to override any weird stuff. But then my app does not start and it complains about a syntax error exactly on the spot of insertion "datetime:". (when I look I can not locate that unexisting syntax error with my single eye).

manitu
  • 1,189
  • 10
  • 16
  • Smudge, You where right! I switched to rails 2.3.9 and things are working as they should again. – manitu Dec 08 '10 at 20:55