bug rails-18n in rails edge

40 views
Skip to first unread message

jpaulolins

unread,
Aug 8, 2008, 9:44:42 AM8/8/08
to rails-i18n
Hi,

I'm using internationalization in rails-edge for testing . That's very
pretty good feature.
My problems beginning when use method error_messages_for :
<%= error_messages_for :user %>

The problem occurring because method full_messages of Active Record
receive one Array whem should receive one string on line 170.
The problem can be ease solved adding to_s on message variable but I
think that isn't good form to solve it.

This problem is consequence of my locale file don't have none set
default messages for Active Record for instance:
:active_record => {
:error_messages => {
:inclusion => "ain't included in the list"
}
}

But it should be treated...

Suggestions?

Sven Fuchs

unread,
Aug 9, 2008, 5:38:27 AM8/9/08
to rails...@googlegroups.com
Hey,

welcome to the list :)

Thanks for the headsup! I think somebody already posted this before
here. I'll have a look at the issue this weekend.
--
sven fuchs sven...@artweb-design.de
artweb design http://www.artweb-design.de
grünberger 65 + 49 (0) 30 - 47 98 69 96 (phone)
d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile)




Sven Fuchs

unread,
Aug 10, 2008, 12:25:18 PM8/10/08
to rails...@googlegroups.com
Hey,

I can't reproduce the issues you guys are having with
error_messages_for. Can you provide me with some hints how to
reproduce this?

What I've done:

rails rails-i18n
cd rails-i18n/
ln -s ~/Server/projects/i18n/rails ~/Server/projects/i18n/rails-i18n/
vendor/rails
script/generate scaffold user
rake db:migrate
mongrel_rails start

In the user model I've added:

class User < ActiveRecord::Base
validates_presence_of :name
end

Then when I went to http://localhost:3000/users/new and clicked
"Create" I got the expected error message:

1 error prohibited this user from being saved
There were problems with the following fields:
Name can't be blank

I then thought the error might be related to Iain's plugin and
installed it:

script/plugin install git://github.com/iain/i18n_yaml.git
mongrel_rails start

Still no dice. What am I missing?

iain

unread,
Aug 10, 2008, 6:29:00 PM8/10/08
to rails-i18n
Hi

It's not my plugin, it's when choosing another locale.

Here is the relevant part of the error:

Processing PostsController#create (for 192.168.1.13 at 2008-08-11
00:27:28) [POST]

Session ID:
BAh7CDoLbG9jYWxlIgdubDoMY3NyZl9pZCIlNDhjYzhmMjk3OGEwMDg5NTc5ODI2OGQ3ZTlmYWQyN2UiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA=--5cc25931b3b982152692b9a028a168570d384539

Parameters: {"commit"=>"Create", "post"=>{"title"=>""},
"authenticity_token"=>"021d928e2de55a18ffd94cd7bc22f41d984ee69b",
"action"=>"create", "controller"=>"posts"}

Locale selected: nl

Cache miss: locales/nl ({:force=>true})

Cache write (will save 0.00025): locales/nl

Rendering template within layouts/posts

Rendering posts/new

Compiling template _run_erb_47app47views47posts47new46html46erb





ActionView::TemplateError (can't convert Array into String) on line #4
of app/views//new.html.erb:

1: <h1>New post</h1>

2:

3: <% form_for(@post) do |f| %>

4: <%= f.error_messages %>

5:

6: <p>

7: <%= f.label :title %><br />



vendor/rails/activerecord/lib/active_record/validations.rb:171:in `
+'

vendor/rails/activerecord/lib/active_record/validations.rb:171:in
`full_messages'

vendor/rails/activerecord/lib/active_record/validations.rb:163:in
`each'

vendor/rails/activerecord/lib/active_record/validations.rb:163:in
`full_messages'

vendor/rails/activerecord/lib/active_record/validations.rb:162:in
`each_key'

vendor/rails/activerecord/lib/active_record/validations.rb:162:in
`full_messages'

vendor/rails/actionpack/lib/action_view/helpers/
active_record_helper.rb:201:in `error_messages_for'

vendor/rails/activesupport/lib/active_support/core_ext/
enumerable.rb:61:in `map'

vendor/rails/activesupport/lib/active_support/core_ext/
enumerable.rb:61:in `sum'

vendor/rails/actionpack/lib/action_view/helpers/
active_record_helper.rb:201:in `error_messages_for'

vendor/rails/activesupport/lib/active_support/core_ext/object/
misc.rb:48:in `with_options'

vendor/rails/actionpack/lib/action_view/helpers/
active_record_helper.rb:192:in `error_messages_for'

vendor/rails/actionpack/lib/action_view/helpers/form_helper.rb:
790:in `error_messages'

app/views/posts/new.html.erb:4



On Aug 10, 6:25 pm, Sven Fuchs <svenfu...@artweb-design.de> wrote:
> Hey,
>
> I can't reproduce the issues you guys are having with  
> error_messages_for. Can you provide me with some hints how to  
> reproduce this?
>
> What I've done:
>
> rails rails-i18n
> cd rails-i18n/
> ln -s ~/Server/projects/i18n/rails ~/Server/projects/i18n/rails-i18n/
> vendor/rails
> script/generate scaffold user
> rake db:migrate
> mongrel_rails start
>
> In the user model I've added:
>
> class User < ActiveRecord::Base
>    validates_presence_of :name
> end
>
> Then when I went tohttp://localhost:3000/users/newand clicked  
> > sven fuchs         svenfu...@artweb-design.de
> > artweb design              http://www.artweb-design.de
> > grünberger 65             + 49 (0) 30 - 47 98 69 96 (phone)
> > d-10245 berlin             + 49 (0) 171 - 35 20 38 4 (mobile)
>
> --
> sven fuchs              svenfu...@artweb-design.de

João Paulo Lins

unread,
Aug 10, 2008, 7:41:52 PM8/10/08
to rails...@googlegroups.com
Exactly. You need set another locale different of en-US (default in  rails).

Sven you can simulate problem using console:

joao@jarvis:~/ruby/app$ script/console
>> I18n.locale
=> "en-US"
>> I18n.store_translations 'pt-br',
?> :error => 'teste'
=> {:error=>"teste"}
>> I18n.locale
=> "en-US"
>> I18n.locale = 'pt-br'
=> "pt-br"
>> I18n.locale
=> "pt-br"
>> I18n.t(:error)
=> "teste"
>> user = User.new
=> #<User id: nil, login: nil, name: "", email: nil, gender: nil, crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, remember_token: nil, remember_token_expires_at: nil, activation_code: nil, activated_at: nil>
>> user.save
=> false
>> user.errors
=> #<ActiveRecord::Errors:0xb719abec @base=#<User id: nil, login: nil, name: "", email: nil, gender: nil, crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, remember_token: nil, remember_token_expires_at: nil, activation_code: nil, activated_at: nil>, @errors={"password_confirmation"=>[[:"custom.user.password_confirmation.blank", :blank]], "gender"=>[[:"custom.user.gender.blank", :blank], :"custom.user.gender.wrong_length"], "login"=>[[:"custom.user.login.blank", :blank], :too_short, "use only letters, numbers, and .-_@ please."], "password"=>[[:"custom.user.password.blank", :blank], :too_short], "email"=>[[:"custom.user.email.blank", :blank], :too_short, "should look like an email address."]}>
>> user.errors.full_messages
TypeError: can't convert Array into String
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:171:in `+'
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:171:in `full_messages'
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:163:in `each'
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:163:in `full_messages'
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:162:in `each_key'
    from /home/joao/ruby/app/vendor/rails/activerecord/lib/active_record/validations.rb:162:in `full_messages'
    from (irb):11

Sven Fuchs

unread,
Aug 13, 2008, 7:27:18 AM8/13/08
to rails...@googlegroups.com
Ok, thanks for the guidance, Iain and João. That was very helpful.

I've briefly looked into it and the behaviour occurs when an actual
translation is missing for either the default ActiveRecord validation
message or the custom validation message for the particular model.

It works with the default validation error message being present in
the translations: http://pastie.org/private/besvgfms1kmxha8puyb6w

It also works when only a custom translation for the model/attribute/
validation is present: http://pastie.org/private/2lod2ryxmqvi1q4sjkufda

Looking at how these errors are generated I'm pretty sure the error is
related to this weird behaviour of the I18n::SimpleBackend's default
option:

# with no translations existing at all:
>> I18n.t :foo, :default => [:bar, :baz]
=> [:bar, :baz]

... which is just crap of course. I think there's not even a test case
covering this.

I'll go and fix that asap.
> Processing PostsController#create (for MailScanner warning:
> numerical links are often malicious: 192.168.1.13 at 2008-08-11
--
sven fuchs sven...@artweb-design.de

Sven Fuchs

unread,
Aug 13, 2008, 7:57:43 AM8/13/08
to rails...@googlegroups.com
I think I have this fixed in both I18n and Rails now:

http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a4023644e5ba8b839
http://github.com/svenfuchs/rails/tree/906e79396badfe9fb6b7f0457e835e5f1a9b09b2

Also, I've slightly changed the way AR::Errors#generate_message looks
up translations:

http://github.com/svenfuchs/rails/commit/e3ecc3375fef4faa807638ff9e9cf309094272bd

So now, with a missing translation we'd get something like:

"translation missing: pt-BR, active_record, error_messages, custom,
user, password, blank"

... which is still not perfect of course, but certainly better (cause
it now names the class, attribute and validation).

iain

unread,
Aug 13, 2008, 2:11:53 PM8/13/08
to rails-i18n
Nice to know that it's fixed. Don't worry about
AR::Errors#generate_message too much. I already found that problem
during the scope cleanup. It rewrote the whole thing, just tying up
some loose ends before I'll send you the patch.

I'm not that familiar with git in how it handles conflicts though.
What should I do to give you a proper patch? Pull you're changes and
overwrite it with my own work, so it'll create a patch that won't
conflict? I dealt with enough problems like this in SVN, but not yet
with git, so some advice would be most helpful.



On Aug 13, 1:57 pm, Sven Fuchs <svenfu...@artweb-design.de> wrote:
> I think I have this fixed in both I18n and Rails now:
>
> http://github.com/svenfuchs/i18n/commit/6c04ca86c87f97dc78f07c2a40236...http://github.com/svenfuchs/rails/tree/906e79396badfe9fb6b7f0457e835e...
>
> Also, I've slightly changed the way AR::Errors#generate_message looks  
> up translations:
>
> http://github.com/svenfuchs/rails/commit/e3ecc3375fef4faa807638ff9e9c...
> > sven fuchs         svenfu...@artweb-design.de
> > artweb design              http://www.artweb-design.de
> > grünberger 65             + 49 (0) 30 - 47 98 69 96 (phone)
> > d-10245 berlin             + 49 (0) 171 - 35 20 38 4 (mobile)
>
> --
> sven fuchs              svenfu...@artweb-design.de

Sven Fuchs

unread,
Aug 13, 2008, 2:48:40 PM8/13/08
to rails...@googlegroups.com
Hey Iain,

On 13.08.2008, at 20:11, iain wrote:
> Nice to know that it's fixed. Don't worry about
> AR::Errors#generate_message too much. I already found that problem
> during the scope cleanup. It rewrote the whole thing, just tying up
> some loose ends before I'll send you the patch.

Hu? Ah, ok. I'm curious :) You're sure the behaviour remains the same?
That's great then.

> I'm not that familiar with git in how it handles conflicts though.
> What should I do to give you a proper patch? Pull you're changes and
> overwrite it with my own work, so it'll create a patch that won't
> conflict? I dealt with enough problems like this in SVN, but not yet
> with git, so some advice would be most helpful.

Yeah, maybe you'd just clone my rails i18n branch edit that and then
send me a pull request. Or a patch.

As I'm not going to do anything in there for the next couple of days
there won't be any problems with conflicts.

So, iirc it's:

git clone git://github.com/svenfuchs/rails-i18n.git
git branch i18n origin/i18n
git checkout i18n

The last both lines should create a local branch i18n which refers to
the i18n branch in my github repo and then switch to that branch.
--
sven fuchs sven...@artweb-design.de
Reply all
Reply to author
Forward
0 new messages