Interning empty string error in Ruby on Rails

I don’t like writing short posts about fixing code errors but I think this one deserves a quick shout out. If you get an error in your Rails application that says “interning empty string”, there could be something wrong with an error message in your validations. For example, I had something like:

def geocoding_works_when_geotarget_is_true
    if geotarget and (self.lat == nil or self.lng == nil or self.address_changed?)
      errors.add("Provide better location information so that we can geotarget your reminders.") unless geocode
    end
end

The ‘.’ in my error message caused an “interning empty string” error. I hope I save someone an hour by posting this.

No TweetBacks yet. (Be the first to Tweet this post)
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis

If you enjoyed this post, make sure you subscribe to my RSS feed!

This entry was posted in Software and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

11 Comments

  1. Posted January 1, 2010 at 8:53 am | Permalink

    Excellent post. saved me hours of digging into the problem. Did you find out why this problem occurs?

  2. Posted January 2, 2010 at 12:15 pm | Permalink

    Haven’t looked into it much further. Drop a comment if you find out.

  3. Sean McCleary
    Posted February 9, 2010 at 12:46 am | Permalink

    Thank you for this post. You saved me a ton of debugging time. That is a strange Rails bug.

  4. Posted February 12, 2010 at 10:35 am | Permalink

    Thank you so much for this. I murdered an hour on this before resorting to Google. Found your page right away, and in my case it was “…” in the error message causing the problem.

  5. Posted February 12, 2010 at 10:39 am | Permalink

    I’m glad this is saving people time. It’s sort of a lame post but serves the intended purpose.

  6. Posted March 29, 2010 at 3:36 pm | Permalink

    This is one of the most random bugs I’ve encountered.

    Thank you for the time that you just saved me, I’ve already wasted enough.
    I wish I had Googled this sooner.

  7. Posted May 17, 2010 at 1:14 am | Permalink

    thanks, just saved me some headaches with an old codebase!

  8. N
    Posted December 22, 2010 at 7:01 pm | Permalink

    Thank you. Your post helped me solve this silly error. Wish I had googled the solution a lot sooner :-)

  9. Posted January 29, 2011 at 8:33 pm | Permalink

    Obviously, this is different from your case, but I traced the same error to a piece of code that used the .to_sym method. And I reproduced it in the console:

    ruby-1.8.7-p174 :084 > a = ‘fred’
    => “fred”
    ruby-1.8.7-p174 :085 > a.to_sym
    => :fred
    ruby-1.8.7-p174 :086 > a = ”
    => “”
    ruby-1.8.7-p174 :087 > a.to_sym
    ArgumentError: interning empty string
    from (irb):87:in `to_sym’
    from (irb):87

    It was fine in Rails 2.2. Broke as I upgraded to Rails3.

  10. Eduard
    Posted February 22, 2011 at 3:30 am | Permalink

    Oh wow, thanks a lot. I had a “.” in my i18n translation file that was used for the validation error.
    Saved me a lot of time and nerves.

  11. Posted November 15, 2011 at 2:42 pm | Permalink

    You should also check your view file, I had one with the filename “title..html.erb”

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">