time_ago_in_words问题

时间:2009-12-31 17:21:28

标签: ruby-on-rails

我遇到了一个问题,我刚刚使用time_ago_in_words遇到了(出于某种原因)。发表帖子后,我得到了

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

我也没做任何有趣的事情,只是调用一个小帮手函数

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

现在,这已经很好地工作了很长时间,然后我尝试今天早上发布一个帖子,它开始抛出先前的异常。有什么想法吗?

编辑:再次发生,所以这里是一个完整的堆栈跟踪请求。

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)

2 个答案:

答案 0 :(得分:5)

例如,你可能会这样搞砸了:

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

而不是:

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

是的,当我发现自己的错误时,我感到很生气......应该更好地记录下来

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

答案 1 :(得分:0)

你的语言环境文件可能搞砸了。您可能需要仔细检查config/locale/en.ymlhttp://gist.github.com/rails/rails/blob/master/actionpack/lib/action_view/locale/en.yml