# Encoding::UTF\_8 missing?

**URL:** <https://www.ruby-forum.com/t/encoding-utf-8-missing/178949>\
**Category:** Rails\
**Created:** [November 13, 2009, 11:10pm UTC](https://www.ruby-forum.com/t/encoding-utf-8-missing/178949 "2009-11-13T23:10:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [November 13, 2009, 11:10pm UTC](https://www.ruby-forum.com/t/encoding-utf-8-missing/178949/1 "2009-11-13T23:10:58Z")

</div>

I’ve just done a fresh reinstall of OS X Snow Leopard on my mac, and I’m  
having all kinds of problems with Rails, but the latest problem has me  
stumped.

Whenever I run rake db:seed to populate my database I hit the following  
error:

\*\* Invoke db:seed (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Execute db:seed  
rake aborted!  
uninitialized constant ActiveSupport::Multibyte::Chars::Encoding  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/dependencies.rb:105:in  
`const_missing' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/multibyte/chars.rb:86:in`initialize’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/core\_ext/string/multibyte.rb:44:in  
`new' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/string/multibyte.rb:44:in`mb\_chars’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/validations.rb:798:in  
`validates_uniqueness_of' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:468:in`validates\_each’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/validations.rb:465:in  
`each' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:465:in`validates\_each’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/callbacks.rb:182:in  
`call' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:182:in`evaluate\_method’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/callbacks.rb:166:in  
`call' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:90:in`run’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/callbacks.rb:90:in  
`each' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:90:in`send’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/callbacks.rb:90:in  
`run' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/callbacks.rb:276:in`run\_callbacks’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/validations.rb:1098:in  
`valid_without_callbacks?' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/callbacks.rb:315:in`valid\_without\_lifecycles?’  
/Library/Ruby/Gems/1.8/gems/hobo-0.8.10/lib/hobo/lifecycles.rb:67:in  
`valid?' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:1077:in`save\_without\_dirty’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/dirty.rb:79:in  
`save_without_transactions' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:229:in`send’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/transactions.rb:229:in  
`with_transaction_returning_status' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in`transaction’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/transactions.rb:182:in  
`transaction' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:228:in`with\_transaction\_returning\_status’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/transactions.rb:196:in  
`save' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:208:in`rollback\_active\_record\_state!’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active\_record/transactions.rb:196:in  
`save' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:723:in`create’  
/Users/iainbeeston/Documents/Programs/Ruby/inspect/db/seeds.rb:9  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/dependencies.rb:145:in  
`load_without_new_constant_marking' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:145:in`load’  
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active\_support/dependencies.rb:521:in  
`new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:145:in`load’  
/Library/Ruby/Gems/1.8/gems/rails-2.3.4/lib/tasks/databases.rake:215  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in`execute’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in`execute’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in  
`invoke_with_call_chain' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in`synchronize’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in  
`invoke_with_call_chain' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in`invoke’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in`top\_level’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in`top\_level’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in  
`standard_exception_handling' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in`top\_level’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in`standard\_exception\_handling’  
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' /Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 /usr/bin/rake:19:in`load’  
/usr/bin/rake:19

It turns out that it’s failing when it tries to do validate\_unique on a  
text field. When I look into the rails code that’s throwing the error  
it’s coming up because it can’t find Encoding::UTF\_8. What’s more, if I  
skip db:seed and just start up the webserver I get a different error but  
it comes down to the exact same cause (can’t find Encoding::UTF\_8).

The problem is that I can’t even figure out where this module is  
supposed to be! Is it rails or is it ruby? Or is it expecting a gem that  
I don’t have? I really have no idea (and google isn’t helping much).

My setup is:

Ruby 1.8.7  
Rails 2.3.4  
Database Mysql 5.1 64bit (MySQL gem 2.8.1 also in 64bit)  
OS Mac OSX SNow Leopard 64bit

Has anyone seen this before? Can anyone suggest a fix?

Thanks!

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [November 14, 2009, 5:14am UTC](https://www.ruby-forum.com/t/encoding-utf-8-missing/178949/2 "2009-11-14T05:14:37Z")

</div>

It’s hobo that’s whacking you.

On Nov 13, 5:10 pm, Iain B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [November 14, 2009, 5:35am UTC](https://www.ruby-forum.com/t/encoding-utf-8-missing/178949/3 "2009-11-14T05:35:42Z")

</div>

Encoding shows up in Ruby 1.9 as part of the multibyte change made to  
String. That said, Rails 2.3.4 does make reference to Encoding::UTF\_8  
but those references are conditional. If you look at  
“activesupport-2.3.4/lib/active\_support/core\_ext/string/multibyte.rb”  
you’ll see the gory details.

I can run db:seed with Ruby1.8.7/Rails2.3.4 with no problem.  
ruby --version =\>  
ruby 1.8.7 (2009-06-08 patchlevel 173) [powerpc-darwin9.7.0]  
rails --version =\> Rails 2.3.4  
gem list mysql =\> mysql (2.8.1)  
mysql --version =\>  
mysql Ver 14.14 Distrib 5.1.39, for apple-darwin9.5.0 (powerpc)  
using readline 5.1

database.yml:

development:  
adapter: mysql  
encoding: utf8  
reconnect: false  
socket: /tmp/mysql.sock  
database: auth-1.8\_dev  
pool: 5  
username: \*\*\*\*  
password: \*\*\*\*\*\*\*\*

seeds.rb

Page.create(:title =\> “It’s all about the pie…”,  
:body =\> “Welcome to Journeys”)

On Nov 13, 5:10 pm, Iain B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![tensaiji](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6de8d8/32.png) [@tensaiji](https://www.ruby-forum.com/u/tensaiji)\
**Post date:** [November 14, 2009, 7:22am UTC](https://www.ruby-forum.com/t/encoding-utf-8-missing/178949/4 "2009-11-14T07:22:15Z")

</div>

You got me thinking about dependent gems that I’m using (rather than  
rails) and it turns out that the problem is caused by a gem called  
google-spreadsheet-ruby (it allows you to access and parse google  
spreadsheets from ruby). This gem defines String.force\_encoding for Ruby  
1.8, however, rails is using this method to test whether it’s running on  
top of Ruby 1.8 or Ruby 1.9 - so it think’s it’s using Ruby 1.9 when  
actually it’s using Ruby 1.8, and then quickly hits problems and  
crashes.

I’ve notified the author of the gem and suggested a solution, and I’ve  
patched my own app for now as well (to undefine this method entirely as  
the gem is an unused dependency in my project) and everything’s working  
again. 🙂
