Closed psobot closed 12 years ago
Ah okay, originally, I just patched the Ruby core classes, but this morning I realized that Rails devs would probably want all objects patched.
I'm going to work on a fix for this now. As a temporary step, I would recommend manually requiring "letters/patch/core" and then running Letters.patch!
on all extra objects you care about -- probably ActiveRecord::Base
and ApplicationController
, for example.
Okay, here's a potential solution. Do you get the same error if you replace require "letters"
with require "letters/patch/rails"
? (You will need to run bundle update letters
first.)
I've just been including letters in my Gemfile
with gem "letters"
- and trying gem 'letters', :require => ["letters/patch/rails"]
doesn't seem to work. Any ideas?
It may be that you have to explicitly require the patch right after Bundler.require
in application.rb
. Does that work for you? I may end up writing a Rails-specific gem to make this easier.
Adding require "letters/patch/rails"
in my application.rb
seems to not help - it results in:
rake aborted!
no such file to load -- letters/patch/rails
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:240:in `require'
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:240:in `block in require'
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:640:in `new_constants_in'
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:223:in `load_dependency'
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.2/lib/active_support/dependencies.rb:240:in `require'
/Volumes/why/lndry/config/application.rb:8:in `<top (required)>'
...
Okay, thanks for the trace. Two questions:
Looks like I'm at 0.2.1:
(branch:master*) » bundle show letters
/Users/psobot/.rvm/gems/ruby-1.9.2-p290/gems/letters-0.2.1
I've tried requiring letters/patch/rails
directly after this line in application.rb
:
Bundler.require(*Rails.groups(:assets => %w(development test)))
I also tried sticking it at the end of boot.rb
, to the same effect.
Okay, I made a small mistake in 0.2.1. Could you try upgrading to 0.2.2 and seeing if the same patch works? If it doesn't, would you mind creating a new Rails app and seeing if you can load it with Letters?
Thanks!
I haven't heard back in a while about this, please reopen the ticket if the problem persists.
It's still a problem, I have actionpack 3.2.8 and letters 0.2.3 and facing exactly the same issue, can't use time distance methods like distance_of_time_in_words
So you're requiring "letters/rails/patch" in application.rb and are getting a file not found error?
Ah, I missed the line about loading the patch, working fine - thanx!
Hey - sorry for the delay, but I've just been able to reproduce this issue in a fresh Rails 3.2.0 project. Added gem "letters"
to my Gemfile, require "letters/patch/rails"
in my application.rb
and put the following in an otherwise blank view:
<%=distance_of_time_in_words(Time.now, Time.now + 5) %>
Which results in the following exception on that view:
letters (0.3.1) lib/letters/core_ext.rb:176:in `t'
actionpack (3.2.0) lib/action_view/helpers/date_helper.rb:77:in `block in distance_of_time_in_words'
activesupport (3.2.0) lib/active_support/core_ext/object/with_options.rb:41:in `with_options'
actionpack (3.2.0) lib/action_view/helpers/date_helper.rb:73:in `distance_of_time_in_words'
app/views/welcome/index.html.erb:1:in `_app_views_welcome_index_html_erb__612129154362926409_70147740061220'
Try adding :require => false
to the line in your Gemfile that installs Letters.
D'oh - thanks, now that example works perfectly. Thanks for your help.
Just tried using Letters on an old Rails project of mine, and ran into an odd stack trace after running
rake
:It seems that ActionPack 3.1.2 calls
locale.t
in a block called fromI18n.with_options
. As letters overridest
on all objects, this results in a bad method call. (Not sure if this also happens in later versions of Rails or ActionPack.)