Hello, I upgraded my application from Rails 2 to Rails 3 and ran into a problem. In rails 2 I could use the english name of the record to find it like: Page.find_by_name("Welcome") even though the user chose German as the language (which of course showed the German welcome page. Eversince I switched to Rails 3 (default_locale still :en) I can''t find anything by giving the English name which sucks cause apparently when the user uses German it''d need to use find_by_name("Willkommen") but when the user uses English it''d need to use find_by_name("Welcome"). I don''t really know the id of each page so I can''t use that. How can I solve this problem? Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-12 18:56 UTC
Re: Rails 3: finding a record by name in multilingual app
can you be more specific? On Sun, Sep 12, 2010 at 9:28 AM, Heinz Strunk <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello, > > I upgraded my application from Rails 2 to Rails 3 and ran into a > problem. In rails 2 I could use the english name of the record to find > it like: > Page.find_by_name("Welcome") > even though the user chose German as the language (which of course > showed the German welcome page. > > Eversince I switched to Rails 3 (default_locale still :en) I can''t find > anything by giving the English name which sucks cause apparently when > the user uses German it''d need to use find_by_name("Willkommen") but > when the user uses English it''d need to use find_by_name("Welcome"). > > I don''t really know the id of each page so I can''t use that. How can I > solve this problem? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-12 22:07 UTC
Re: Rails 3: finding a record by name in multilingual app
Well, I have been using Page.find_by_name("Welcome") in my code all the time when I was on Rails 2 (and globalize2, of course) and no matter what language was selected by the user it was always possible to load the welcome page with this command: Page.find_by_name("Welcome") Eversince I switched to Rails 3 Page.find_by_name("Welcome") doesn''t work anymore if there''s another language selected but English which sucks cause I''d need to wrap an if clause checking for the language and then do one of these: Page.find_by_name("Welcome") for English Page.find_by_name("Willkommen") for German Page.find_by_name("Bienvenido") for Spanish which is very stupid but I hope you''re catching my drift. The problem is that I can''t use the id but have to use the name which is multilingual. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-13 16:57 UTC
Re: Rails 3: finding a record by name in multilingual app
What that not specific enough? I really don''t know how to proceed right now cause there''s no proper way to avoid name. This is my latest approach which I don''t like at all but well... Page.find(Fixtures.identify(:welcome)) Works for every language but not so nice. Anyone else got a better solution? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Schuerig
2010-Sep-13 17:17 UTC
Re: Rails 3: finding a record by name in multilingual app
On Monday 13 September 2010, Heinz Strunk wrote:> Well, I have been using Page.find_by_name("Welcome") in my code all > the time when I was on Rails 2 (and globalize2, of course) and no > matter what language was selected by the user it was always possible > to load the welcome page with this command: > Page.find_by_name("Welcome") > > Eversince I switched to Rails 3 Page.find_by_name("Welcome") doesn''t > work anymore if there''s another language selected but English which > sucks cause I''d need to wrap an if clause checking for the language > and then do one of these:This is completely fishy. Rails is not supposed to translate strings behind your back. Are you any extensions (gems, plugins) that may try to be helpful in the wrong way? Out of the box, #find_by_name behaves exactly the same as #find_by_foobar, which is to say, it executes an SQL statement containing a comparison of column "name" with the string you provide. It looks like a call to I18n.translate has been slipped in somewhere. Do you get the same result for Page.where(:name => ''Welcome'').first? In order to find the real cause, your best bet is to use the debugger and step into the misbehaving statement. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-13 18:40 UTC
Re: Rails 3: finding a record by name in multilingual app
> This is completely fishy. Rails is not supposed to translate strings > behind your back. Are you any extensions (gems, plugins) that may try to > be helpful in the wrong way?Well, I used globalize2 when I used Rails 2.3.8 and everything worked perfectly fine but no new gems or anything eversince. Must be globalize3 or something...> > Out of the box, #find_by_name behaves exactly the same as > #find_by_foobar, which is to say, it executes an SQL statement > containing a comparison of column "name" with the string you provide. It > looks like a call to I18n.translate has been slipped in somewhere. > > Do you get the same result for Page.where(:name => ''Welcome'').first?where doesn''t work because it''s in a different table: Page.where(:name => ''Willkommen'') ActiveRecord::StatementInvalid: Mysql::BadFieldError: Unknown column ''pages.name'' in ''where clause'': SELECT `pages`.* FROM `pages` WHERE (`pages`.`name` = ''Willkommen'')> > In order to find the real cause, your best bet is to use the debugger > and step into the misbehaving statement.I guess I have no other choice... Just to make my problem a bit more clear: irb(main):030:0> I18n.locale = :de => :de irb(main):031:0> Page.find_by_name("Welcome") => [] irb(main):032:0> Page.find_by_name("Willkommen") => [#<Page id: 93372675, text: "blah blah", created_at: "2010-09-12 12:55:41", updated_at: "2010-09-12 12:55:41">] irb(main):033:0> I18n.locale = :en => :en irb(main):034:0> Page.find_by_name("Welcome") => [#<Page id: 93372675, text: "blah blah", created_at: "2010-09-12 12:55:41", updated_at: "2010-09-12 12:55:41">] irb(main):035:0> Page.find_by_name("Willkommen") => [] Before I upgraded to Rails 3 all four queries returned the same result. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-13 19:22 UTC
Re: Re: Rails 3: finding a record by name in multilingual app
sorry for not answering busy. yes i understand what you say now, but it seems that is a problem with the gem. I dont know globalize2 ill read on it and try to help. On Mon, Sep 13, 2010 at 2:40 PM, Heinz Strunk <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > This is completely fishy. Rails is not supposed to translate strings > > behind your back. Are you any extensions (gems, plugins) that may try to > > be helpful in the wrong way? > Well, I used globalize2 when I used Rails 2.3.8 and everything worked > perfectly fine but no new gems or anything eversince. Must be globalize3 > or something... > > > > Out of the box, #find_by_name behaves exactly the same as > > #find_by_foobar, which is to say, it executes an SQL statement > > containing a comparison of column "name" with the string you provide. It > > looks like a call to I18n.translate has been slipped in somewhere. > > > > Do you get the same result for Page.where(:name => ''Welcome'').first? > where doesn''t work because it''s in a different table: > Page.where(:name => ''Willkommen'') > ActiveRecord::StatementInvalid: Mysql::BadFieldError: Unknown column > ''pages.name'' in ''where clause'': SELECT `pages`.* FROM `pages` WHERE > (`pages`.`name` = ''Willkommen'') > > > > In order to find the real cause, your best bet is to use the debugger > > and step into the misbehaving statement. > I guess I have no other choice... > > Just to make my problem a bit more clear: > irb(main):030:0> I18n.locale = :de > => :de > irb(main):031:0> Page.find_by_name("Welcome") > => [] > irb(main):032:0> Page.find_by_name("Willkommen") > => [#<Page id: 93372675, text: "blah blah", created_at: "2010-09-12 > 12:55:41", updated_at: "2010-09-12 12:55:41">] > irb(main):033:0> I18n.locale = :en > => :en > irb(main):034:0> Page.find_by_name("Welcome") > => [#<Page id: 93372675, text: "blah blah", created_at: "2010-09-12 > 12:55:41", updated_at: "2010-09-12 12:55:41">] > irb(main):035:0> Page.find_by_name("Willkommen") > => [] > > Before I upgraded to Rails 3 all four queries returned the same result. > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-13 19:43 UTC
Re: Re: Rails 3: finding a record by name in multilingual app
> yes i understand what you say now, but it seems that is a problem with > the > gem. I dont know globalize2 ill read on it and try to help.Thanks in advance I do appreciate but I''m using globalize3 and not 2 anymore :) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-13 19:47 UTC
Re: Re: Re: Rails 3: finding a record by name in multilingual app
so is it working? On Mon, Sep 13, 2010 at 3:43 PM, Heinz Strunk <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > yes i understand what you say now, but it seems that is a problem with > > the > > gem. I dont know globalize2 ill read on it and try to help. > > Thanks in advance I do appreciate but I''m using globalize3 and not 2 > anymore :) > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-13 20:03 UTC
Re: Re: Re: Rails 3: finding a record by name in multilingual app
Nope not yet but you said you''ll try to help and appreciate it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Schuerig
2010-Sep-13 20:54 UTC
Re: Rails 3: finding a record by name in multilingual app
On Monday 13 September 2010, Heinz Strunk wrote:> > This is completely fishy. Rails is not supposed to translate > > strings behind your back. Are you any extensions (gems, plugins) > > that may try to be helpful in the wrong way? > > Well, I used globalize2 when I used Rails 2.3.8 and everything worked > perfectly fine but no new gems or anything eversince. Must be > globalize3 or something... > > > Out of the box, #find_by_name behaves exactly the same as > > #find_by_foobar, which is to say, it executes an SQL statement > > containing a comparison of column "name" with the string you > > provide. It looks like a call to I18n.translate has been slipped > > in somewhere. > > > > Do you get the same result for Page.where(:name => > > ''Welcome'').first? > > where doesn''t work because it''s in a different table: > Page.where(:name => ''Willkommen'') > ActiveRecord::StatementInvalid: Mysql::BadFieldError: Unknown column > ''pages.name'' in ''where clause'': SELECT `pages`.* FROM `pages` WHERE > (`pages`.`name` = ''Willkommen'')Well, after looking at the globalize3 code (specifically lib/globalize/active_record/class_methods.rb), I see *why* you get the result you do. The code is actually quite ingenious (or flabberghastly, depending on how you look at it). Anyway, I think(!) you get what you want, if you simply write with_locale(:en) { Page.find_by_name(''Welcome'') } For more details, have a look at the tests that come with globalize3. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Heinz Strunk
2010-Sep-14 15:44 UTC
Re: Rails 3: finding a record by name in multilingual app
Michael Schuerig wrote:> with_locale(:en) { > Page.find_by_name(''Welcome'') > }Thanks, but there''s a little something that makes me not being able to use it. I got another field called content which has the actually content of the page. When I use it with with_locale I get the english content as well. I though of adding a "key" field so I can always find it by it''s key, rename "name" to "title" and everything should, work if I do find_by_key(). -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.