Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

time_ago_in_words issue

I have an issue that I just ran into (for some reason) using time_ago_in_words. After publishing a post, I got

translation data {"one"=>"1 minute", "other"=>"{{count}} minutes"} can not be used with :count => 9

I am not really doing anything that interesting either, just calling a small helper function

def friendly_publish_date(post)
  return '' if post.publish_date.nil?

  if post.publish_date >= 1.day.ago
    "#{time_ago_in_words post.publish_date} ago"
  else
    post.publish_date
  end
end

Now, this has worked fine for ages, then I try publishing a post this morning, and it starts throwing the earlier exception. Any ideas?

EDIT: Happened again, so here is a full stack trace as requested.

Processing PostsController#index (for 74.213.163.234 at 2010-01-05 11:43:26) [GET]
  Parameters: {"action"=>"index", "controller"=>"posts"}

Rendering template within layouts/application
Rendering posts/index

ActionView::TemplateError (translation data {"one"=>"less than a minute", "other"=>"less than {{count}} minutes"} can not be used with :count => 1) on line #5 of app/views/posts/_post.html.erb:
2:   <header>
3:     <div class='preheader'>
4:       <time datetime="<%= datetime_format(post.publish_date) %>">
5:         <%= friendly_publish_date(post) %>
6:       </time>
7:       <h6>
8:         posted by Matt Briggs

    /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/i18n-0.2.0/lib/i18n/backend/simple.rb:149:in `pluralize'
    /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/i18n-0.2.0/lib/i18n/backend/simple.rb:35:in `translate'
    /opt/ruby-enterprise-1.8.6-20090610/lib/ruby/gems/1.8/gems/i18n-0.2.0/lib/i18n.rb:195:in `t'
    app/helpers/posts_helper.rb:17:in `friendly_publish_date'
    app/views/posts/_post.html.erb:5
    app/views/posts/index.html.erb:22
    app/views/posts/index.html.erb:19:in `each'
    app/views/posts/index.html.erb:19
    app/controllers/posts_controller.rb:9:in `index'
    passenger (2.2.8) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
    passenger (2.2.8) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
    passenger (2.2.8) lib/phusion_passenger/railz/application_spawner.rb:385:in`start_request_handler'
    passenger (2.2.8) lib/phusion_passenger/railz/application_spawner.rb:343:in`handle_spawn_application'
    passenger (2.2.8) lib/phusion_passenger/utils.rb:184:in `safe_fork'
    passenger (2.2.8) lib/phusion_passenger/railz/application_spawner.rb:341:in`handle_spawn_application'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:163:in `start'
    passenger (2.2.8) lib/phusion_passenger/railz/application_spawner.rb:209:in`start'
    passenger (2.2.8) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
    passenger (2.2.8) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
    passenger (2.2.8) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
    passenger (2.2.8) lib/phusion_passenger/abstract_server_collection.rb:80:in`synchronize'
    passenger (2.2.8) lib/phusion_passenger/abstract_server_collection.rb:79:in`synchronize'
    passenger (2.2.8) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
    passenger (2.2.8) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
    passenger (2.2.8) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:352:in `__send__'

    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
    passenger (2.2.8) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Rendering /home/mattcode/mattcode.net/public/500.html (500 Internal Server Error)
like image 595
Matt Briggs Avatar asked Dec 31 '09 17:12

Matt Briggs


1 Answers

For instance maybe you messed up like this:

  activerecord:
    models:
      account:
        attributes:
          email:
            one: "1 email"
            other: "{{count}} emails"

instead of:

  activerecord:
    attributes:
      account:
        email:
          one: "1 email"
          other: "{{count}} emails"

Yes I was pissed of either when I discovered my mistake... It should be better documented

source: http://groups.google.com/group/rails-i18n/browse_thread/thread/0a0d0cfcad63ff4f/9eb3c2dd98d19407?lnk=raot

like image 179
Piotr Mąsior Avatar answered Oct 18 '22 03:10

Piotr Mąsior