I am using your distance_of_time_in_words from dotiw gem but not working fine.
I am with rails 3.1 + Mongoid.
This is the method in my view
<% @houses.each do |house| %>
.
.
.
<%= distance_of_time_in_words house.created_at , :only => [:days, :hours, :minutes] %>
.
.
.
<% end %>
I catch the error message:
can't convert Hash into an exact number
In my model I have the include Mongoid::Timestamps with :created_at attribute
However the other 2 methods time_ago_in_words and distance_of_time_in_words_to_now working fine.
Whats the matter?
This is the trace
activesupport (3.1.0) lib/active_support/core_ext/time/calculations.rb:266:in `-'
activesupport (3.1.0) lib/active_support/core_ext/time/calculations.rb:266:in `minus_with_duration'
activesupport (3.1.0) lib/active_support/core_ext/time/calculations.rb:277:in `minus_with_coercion'
dotiw (1.1.1) lib/dotiw.rb:17:in `distance_of_time_in_words_hash'
dotiw (1.1.1) lib/dotiw.rb:26:in `distance_of_time_in_words'
app/views/houses/index.html.erb:11:in `block in _app_views_houses_index_html_erb__571604405_92462440'
app/views/houses/index.html.erb:5:in `each'
app/views/houses/index.html.erb:5:in `_app_views_houses_index_html_erb__571604405_92462440'
actionpack (3.1.0) lib/action_view/template.rb:144:in `block in render'
activesupport (3.1.0) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.0) lib/action_view/template.rb:142:in `render'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:40:in `block (2 levels) in render_template'
actionpack (3.1.0) lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.0) lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:39:in `block in render_template'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:38:in `render_template'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:12:in `block in render'
actionpack (3.1.0) lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats'
actionpack (3.1.0) lib/action_view/renderer/template_renderer.rb:9:in `render'
actionpack (3.1.0) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.1.0) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.1.0) lib/abstract_controller/rendering.rb:120:in `_render_template'
actionpack (3.1.0) lib/action_controller/metal/streaming.rb:250:in `_render_template'
actionpack (3.1.0) lib/abstract_controller/rendering.rb:114:in `render_to_body'
actionpack (3.1.0) lib/action_controller/metal/renderers.rb:30:in `render_to_body'
actionpack (3.1.0) lib/action_controller/metal/compatibility.rb:43:in `render_to_body'
actionpack (3.1.0) lib/abstract_controller/rendering.rb:99:in `render'
actionpack (3.1.0) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.1.0) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/home/ubuntu/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
activesupport (3.1.0) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.1.0)开发者_JAVA百科 lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:78:in `cleanup_view_runtime'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.1.0) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.1.0) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.1.0) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.1.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.1.0) lib/active_support/callbacks.rb:416:in `_run__105529287__process_action__379420373__callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:386:in `_run_process_action_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `block in instrument'
activesupport (3.1.0) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.1.0) lib/active_support/notifications.rb:53:in `instrument'
actionpack (3.1.0) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.1.0) lib/action_controller/metal/params_wrapper.rb:201:in `process_action'
actionpack (3.1.0) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.1.0) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.1.0) lib/action_controller/metal.rb:193:in `dispatch'
actionpack (3.1.0) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.1.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:65:in `dispatch'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:29:in `call'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:75:in `optimized_each'
rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
actionpack (3.1.0) lib/action_dispatch/routing/route_set.rb:531:in `call'
oa-core (0.3.0) lib/omniauth/strategy.rb:44:in `call!'
oa-core (0.3.0) lib/omniauth/strategy.rb:30:in `call'
mongoid (2.3.1) lib/rack/mongoid/middleware/identity_map.rb:33:in `block in call'
mongoid (2.3.1) lib/mongoid.rb:130:in `unit_of_work'
mongoid (2.3.1) lib/rack/mongoid/middleware/identity_map.rb:33:in `call'
warden (1.0.6) lib/warden/manager.rb:35:in `block in call'
warden (1.0.6) lib/warden/manager.rb:34:in `catch'
warden (1.0.6) lib/warden/manager.rb:34:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.3.3) lib/rack/etag.rb:23:in `call'
rack (1.3.3) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/flash.rb:243:in `call'
rack (1.3.3) lib/rack/session/abstract/id.rb:195:in `context'
rack (1.3.3) lib/rack/session/abstract/id.rb:190:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/cookies.rb:326:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (3.1.0) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
activesupport (3.1.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.0) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/reloader.rb:68:in `call'
rack (1.3.3) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.0) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.3) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.0) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.3) lib/rack/lock.rb:15:in `call'
actionpack (3.1.0) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.0) lib/rails/engine.rb:455:in `call'
railties (3.1.0) lib/rails/rack/content_length.rb:16:in `call'
railties (3.1.0) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.3) lib/rack/handler/mongrel.rb:77:in `process'
mongrel (1.2.0.pre2) lib/mongrel.rb:165:in `block in process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `each'
mongrel (1.2.0.pre2) lib/mongrel.rb:164:in `process_client'
mongrel (1.2.0.pre2) lib/mongrel.rb:291:in `block (2 levels) in run'
distance_of_time_in_words
takes two times and then works out the distance between them. In your code, you're passing a time and then a hash and then dotiw
is attempting to compare the two.
If you're only interested in the distance of one time to now, how about using time_ago_in_words
?
精彩评论