« Re-syncing a Cherry eVolution Orca wireless desktopSwitching to b2evolution »

Edge Rails and gettext: undefined method file_exists? (NoMethodError)

Permalink Posted by Andreas Email on February 12, 2008 at 04:08 pm. Categories: Ruby on Rails

After updating to the latest edge Rails via SVN today, my local development webserver suddenly started to respond with a 500 application error for every request. The mongrel console revealed:

Code:

NoMethodError (undefined method `file_exists?' for #<ActionView::Base:0x2aaaac3eee10>):
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.90.0/lib/gettext/rails.rb:280:in `render_file'
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.90.0/lib/gettext/rails.rb:278:in `each'
    /usr/lib64/ruby/gems/1.8/gems/gettext-1.90.0/lib/gettext/rails.rb:278:in `render_file'
    /vendor/rails/actionpack/lib/action_controller/base.rb:1107:in `render_for_file'
    /vendor/rails/actionpack/lib/action_controller/base.rb:841:in `render_with_no_layout'
    :
    :

Digging deeper, I found out that the method ActionView::Base#file_exists? has been moved to a different place in Rails' Changeset 8683. Fortunately, fixing it is easy.

Follow up:

As a workaround until either rails or gettext is fixed, you can simply drop the following lines somewhere into your rails application (e.g. I added it to config/initializers/gettext.rb, which I use to pull in gettext support):

Code:

module ActionView
  class Base
    delegate :file_exists?, :to => :finder unless respond_to?(:file_exists?)
  end
end

This snippet adds the method file_exists? to ActionView::Base if it doesn't exist and delegates calls to it to the finder (which is the place where this method has been moved to in newer rails versions).

Update: Issue reported as ruby-gettext bug #17990.

Update 2008-06-18: In a recent commit, the ActionView::Base#file_exists? method was added again, so the above workaround isn't necessary anymore for Edge Rails and probably Rails 2.1.

Update 2008-08-07: Looks like something was changed again before Rails 2.1 was released. With Rails 2.1, this workaround is still necessary to use gettext.

Tags: , ,

Trackback address for this post

Trackback URL (right click and copy shortcut/link location)

7 comments

Comment from: John D. Rowell [Visitor] · http://www.indaiatuba.info
Thanks Andreas, I just updated my pistonized rails edge and ran into the same problem, even with the latest gettext gem. Didn't try gettext svn though (and don't plan to :P). Cheers!
02/25/08 @ 12:09
Comment from: Antono Vasiljev [Visitor] · http://antono.info
Thank you for your snippet! You saved my time :)
03/23/08 @ 07:11
Comment from: Ramon Cahenzli [Visitor] · http://rca.vmk.zhdk.ch/
*****
Thanks from me, also, especially for the workaround. gettext is already fixed now, I see, so hurray for free software :)
07/11/08 @ 15:33
Comment from: Raul Riera [Visitor]
Hi, this fix doesnt seem to be really "fixed" for Gettext and Rails 2.1 I still get the error

NoMethodFound for init_gettext if I dont have that workaround in my initializers. Any thoughts?
08/06/08 @ 15:31
Comment from: Andreas [Member] Email
Yes indeed it looks like something was changed again before they released Rails 2.1, so this workaround is still necessary to use gettext with Rails 2.1. Hopefully the upcoming i18n interface of the next Rails version will make it easier to keep translation plugins like gettext working.

08/07/08 @ 10:38
Comment from: Raul Riera [Visitor]
Gettext has a new version to fix this issue, thanks for your help
08/07/08 @ 18:01
Comment from: Hallison Batista [Visitor]
*****
Thanks ... this code snippet saved my project.
08/14/08 @ 23:06

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)

Search

Subscribe

Latest articles

Contact me: zoojange@zargony.com epiduaso@zargony.com

powered by b2evolution free blog software