ruby-on-rails – time_ago_in_words问题

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – time_ago_in_words问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个问题,我刚刚遇到(由于某种原因)使用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)

解决方法

例如也许你这样搞砸了:
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

猜你在找的Ruby相关文章