Encoding::UTF_8 missing?

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:ininitialize’
/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:inmb_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:invalidates_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:invalidates_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:inevaluate_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:inrun’
/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:insend’
/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:inrun_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:invalid_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:insave_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:insend’
/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:intransaction’
/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:inwith_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:inrollback_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:increate’
/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:inload’
/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:inload’
/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:inexecute’
/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:inexecute’
/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:insynchronize’
/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:ininvoke’
/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:intop_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:intop_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:intop_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:instandard_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:inload’
/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!

It’s hobo that’s whacking you.

On Nov 13, 5:10 pm, Iain B. [email protected]

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. [email protected]

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. :slight_smile: