# Globalize doesn't work: HELP ME PLEASE

**URL:** <https://www.ruby-forum.com/t/globalize-doesnt-work-help-me-please/111696>\
**Category:** Rails\
**Created:** [August 9, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/globalize-doesnt-work-help-me-please/111696 "2007-08-09T21:41:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianluca\_t](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d78d45/32.png) [@gianluca\_t](https://www.ruby-forum.com/u/gianluca_t)\
**Post date:** [August 9, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/globalize-doesnt-work-help-me-please/111696/1 "2007-08-09T21:41:53Z")

</div>

Hi to all,

seems that Globalize creates wrong sql statements on dynamic finders on  
translated columns (find\_by\_{attribute}) when locale is not en-US.

Globalize Plugin (for\_1\_2) installed on vendor/plugins under application  
root  
Rails 1.2.3  
Ruby 1.8.6  
Mysql Ver 14.12 Distrib 5.0.37, for redhat-linux-gnu (i686) using  
readline 5.0  
Fedora Core 7

Example:

Migration / Table:

db/migrate/001\_test1.rb  
class Test1 \< ActiveRecord::Migration  
def self.up  
create\_table(:test1s, :options =\> ‘DEFAULT CHARSET=UTF8’) do |t|  
t.column :name, :string, :limit =\> 100, :null =\> false  
t.column :description, :string, :limit =\> 100, :null =\> false  
t.column :created\_at, :datetime, :null =\> false  
t.column :updated\_at, :datetime, :null =\> false  
end  
end  
def self.down  
drop\_table :test1s  
end  
end

Model:  
app/models/test1.rb  
class Test1 \< ActiveRecord::Base  
translates :description  
validates\_presence\_of :name, :description  
validates\_uniqueness\_of :name, :description  
end

Configuration:  
config/environment.rb  
… on last line…  
Globalize::Locale.set\_base\_language “en-US”

Run rake db:migrate

Run script/console

t=Test1.new  
=\> #\<Test1:0xb76b1bf8 @attributes={“name”=\>"", “updated\_at”=\>nil,  
“description”=\>"", “created\_at”=\>nil}, @new\_record=true\>  
t.name=“n1”  
=\> “n1”  
t.description=“d1”  
=\> “d1”  
t.save!  
=\> true

Globalize::Locale.set “en-US”  
=\> #\<Globalize::Locale:0xb769db08 @currency\_decimal\_sep=".",  
@currency\_format=nil, @decimal\_sep=".", @language=English,  
@code=“en-US”, @date\_format=nil, @thousands\_sep=",",  
@country=#\<Globalize::Country:0xb76999e0  
@attributes={“date\_format”=\>nil, “currency\_decimal\_sep”=\>".",  
“thousands\_sep”=\>",", “code”=\>“US”, “number\_grouping\_scheme”=\>“western”,  
“english\_name”=\>“United States of America”, “decimal\_sep”=\>".",  
“id”=\>“223”, “currency\_code”=\>“USD”, “currency\_format”=\>nil}\>,  
@number\_grouping\_scheme=:western, @currency\_code=“USD”\>

Test1.find\_by\_description(“d1”)  
=\> #\<Test1:0xb76943b4 @original\_language=English,  
@attributes={“name”=\>“n1”, “updated\_at”=\>“2007-08-09 11:24:49”,  
“id”=\>“3”, “description”=\>“d1”, “created\_at”=\>“2007-08-09 11:24:49”}\>

# All works only because the locale is en-US…

Globalize::Locale.set “it-IT”  
=\> #\<Globalize::Locale:0xb769271c @currency\_decimal\_sep=",",  
@currency\_format=“EURO %n”, @decimal\_sep=",", @language=Italian,  
@code=“it-IT”, @date\_format=nil, @thousands\_sep=".",  
@country=#\<Globalize::Country:0xb768ff08  
@attributes={“date\_format”=\>nil, “currency\_decimal\_sep”=\>",",  
“thousands\_sep”=\>".", “code”=\>“IT”, “number\_grouping\_scheme”=\>“western”,  
“english\_name”=\>“Italy”, “decimal\_sep”=\>",", “id”=\>“106”,  
“currency\_code”=\>“EUR”, “currency\_format”=\>“EURO %n”}\>,  
@number\_grouping\_scheme=:western, @currency\_code=“EUR”\>

Test1.find\_by\_description(“d1”)  
ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your  
SQL syntax; check the manual that corresponds to your MySQL server  
version for the right syntax to use near ‘COALESCE(t\_description.text,  
test1s.description) = ‘d1’) LIMIT 1’ at line 1: SELECT test1s.id,  
test1s.name, test1s.created\_at, test1s.updated\_at,  
COALESCE(t\_description.text, test1s.description) AS description,  
t\_description.text AS description\_not\_base FROM test1s LEFT OUTER  
JOIN globalize\_translations AS t\_description ON t\_description.table\_name  
= ‘test1s’ AND test1s.id = t\_description.item\_id AND t\_description.facet  
= ‘description’ AND t\_description.language\_id = 2600 WHERE (test1s.  
COALESCE(t\_description.text, test1s.description) = ‘d1’) LIMIT 1  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/connection\_adapters/abstract\_adapter.rb:128:in

`log’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/connection\_adapters/mysql\_adapter.rb:243:in

`execute’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/connection\_adapters/mysql\_adapter.rb:399:in

`select’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:7:in

`select\_all’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:427:in

`find\_by\_sql’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:997:in

`globalize\_old\_find\_every’  
from  
./script/…/config/…/config/…/vendor/plugins/for-1.2/lib/globalize/localization/db\_translate.rb:885:in

`find\_every’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:991:in

`find\_initial’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1204:in

`send’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1204:in

`method\_missing’  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active\_support/deprecation.rb:44:in

`silence’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active\_record/base.rb:1204:in

`method\_missing’  
from (irb):9

# And now this not works because the locale is “it-IT” WHY

???

I think this is a Globalize bug but I’m not 100% sure…

Someone can help me ???

Thanks in advance to everyone…

Tex
