I am new to Ruby on Rails. I have read a lot, and bought several books, and now I have started to implement a modified "shopping cart", following the AWDWR-book, with modifications to suit our application (subscriptions and memberships). Having done up to chapter 7 I have had no real problems, except one: Since our customers are Swedish I need the screen names, texts etc to be in swedish, (the internals are ok with English, which we always have used to be prepared for business abroad some day). When I in the .rhtml files write characters ?, ?, and ? (or ?, ?, ?)[these are swedish charactera a a and o, A, A with umlaut characters above] I get a problem: the show up on the screen as a question mark [?] Does not UTF-8 take care of this? How do I adjust the .rhtml files to show Swedish characters? Thanks in advance! Per-Olof -- Posted via http://www.ruby-forum.com/.
>>>>> "Per-Olof" == Per-Olof Hermansson <per-olof.hermansson@massmarketing.se> writes:> When I in the .rhtml files write characters ?, ?, and ? (or ?, ?, > ?)[these are swedish charactera a a and o, A, A with umlaut characters > above] I get a problem: the show up on the screen as a question mark [?]> Does not UTF-8 take care of this?You have to make sure that the rhtml files are actually in UTF-8. -- Calle Dybedahl <calle@cyberpomo.com> http://www.livejournal.com/users/cdybedahl/ "Just about anything can be done if you are demented enough." -- Christopher C. Petro, scary.devil.monastery
Calle Dybedahl wrote:>>>>>> "Per-Olof" == Per-Olof Hermansson <per-olof.hermansson@massmarketing.se> writes: > >> When I in the .rhtml files write characters ?, ?, and ? (or ?, ?, >> ?)[these are swedish charactera a a and o, A, A with umlaut characters >> above] I get a problem: the show up on the screen as a question mark [?] > >> Does not UTF-8 take care of this? > > You have to make sure that the rhtml files are actually in UTF-8. > -- > Calle Dybedahl <calle@cyberpomo.com> > http://www.livejournal.com/users/cdybedahl/ > "Just about anything can be done if you are demented enough." > -- Christopher C. Petro, scary.devil.monasteryI have tried that, but I realize now that I also must configure RoR to be in "UTF-8 mode", and that there are some complications with this. Is there any other way? Per-Olof -- Posted via http://www.ruby-forum.com/.
>>>>> "Per-Olof" == Per-Olof Hermansson <per-olof.hermansson@massmarketing.se> writes:> I have tried that, but I realize now that I also must configure RoR to > be in "UTF-8 mode", and that there are some complications with this.There are? It seems to be working perfectly for me. What complications are you experiencing?> Is there any other way?Make everything Latin-1 instead? Rails itself is fairly encoding-agnostic, as far as I''ve seen. -- Calle Dybedahl <calle@cyberpomo.com> http://www.livejournal.com/users/cdybedahl/ Try again. Try harder. -*- Fail again. Fail better.
> > Is there any other way?Hej! Try putting this snippet in application.rb: def configure_charsets @response.headers["Content-Type"] = "text/html; charset=utf-8" suppress(ActiveRecord::StatementInvalid) do ActiveRecord::Base.connection.execute ''SET NAMES UTF8'' end end If you want to learn more, This is a good article about Rails and Unicode http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/ Magnus ----- www.tickethappy.com - Ticket tracking in a simple and friendly way.
Calle Dybedahl wrote:>>>>>> "Per-Olof" == Per-Olof Hermansson <per-olof.hermansson@massmarketing.se> writes: > >> I have tried that, but I realize now that I also must configure RoR to >> be in "UTF-8 mode", and that there are some complications with this. > > There are? It seems to be working perfectly for me. What complications > are you experiencing? > >> Is there any other way? > > Make everything Latin-1 instead? Rails itself is fairly > encoding-agnostic, as far as I''ve seen. > -- > Calle Dybedahl <calle@cyberpomo.com> > http://www.livejournal.com/users/cdybedahl/ > Try again. Try harder. -*- Fail again. Fail better.I haven?t set the environment.rb to UTF-8 yet, but I read the Wiki:http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings and they take upp some of the issues (strings, sorting etc) -- Posted via http://www.ruby-forum.com/.
magnus Hjelm wrote:>> > Is there any other way? > Hej! > > Try putting this snippet in application.rb: > > def configure_charsets > @response.headers["Content-Type"] = "text/html; charset=utf-8" > suppress(ActiveRecord::StatementInvalid) do > ActiveRecord::Base.connection.execute ''SET NAMES UTF8'' > end > end > > If you want to learn more, This is a good article about Rails and > Unicode > http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/ > > MagnusThanks, I?ll try it, Per-Olof -- Posted via http://www.ruby-forum.com/.
magnus Hjelm wrote:>> > Is there any other way? > Hej! > > Try putting this snippet in application.rb: > > def configure_charsets > @response.headers["Content-Type"] = "text/html; charset=utf-8" > suppress(ActiveRecord::StatementInvalid) do > ActiveRecord::Base.connection.execute ''SET NAMES UTF8'' > end > end > > If you want to learn more, This is a good article about Rails and > Unicode > http://ruphus.com/blog/2005/06/23/getting-unicode-mysql-and-rails-to-cooperate/ > > MagnusThis seems only to have changed the content of fields in tables. That was actually no problem before. I had problems with the .rhtml text, not the content strings of my database. Still get wrong characters of the texts i the .rhtml pages. -- Posted via http://www.ruby-forum.com/.
Per-Olof Hermansson wrote:> Calle Dybedahl wrote: >> Make everything Latin-1 instead? Rails itself is fairly >> encoding-agnostic, as far as I''ve seen.That?s what I had from start. Contents are ok, but problems with the characters in the .rhtml pages. Per-Olof -- Posted via http://www.ruby-forum.com/.
We''re using UTF-8 here and just don''t tell Rails about it. :) So, we''re just moving the character data from the database to the browser or vice-versa as "plain bytes". If you need stuff like sorting/upcase/downcase in Ruby to work correctly, you can try using the "unicode" gem as described on the wiki page: ...using the routines from the Unicode library by Yoshida Masato, available as a gem gem install unicode After that the following functions will be available: Unicode::downcase(string) Unicode::downcase(string) Unicode::normalize etc. -Thomas Am 09.04.2006 um 10:01 schrieb Per-Olof Hermansson:> Calle Dybedahl wrote: >>>>>>> "Per-Olof" == Per-Olof Hermansson <per- >>>>>>> olof.hermansson@massmarketing.se> writes: >> >>> I have tried that, but I realize now that I also must configure >>> RoR to >>> be in "UTF-8 mode", and that there are some complications with this. >> >> There are? It seems to be working perfectly for me. What >> complications >> are you experiencing? >> >>> Is there any other way? >> >> Make everything Latin-1 instead? Rails itself is fairly >> encoding-agnostic, as far as I''ve seen. >> -- >> Calle Dybedahl <calle@cyberpomo.com> >> http://www.livejournal.com/users/cdybedahl/ >> Try again. Try harder. -*- Fail again. Fail better. > > I haven?t set the environment.rb to UTF-8 yet, but I read the > Wiki:http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings > and > they take upp some of the issues (strings, sorting etc) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thomas Fuchs wrote:> We''re using UTF-8 here and just don''t tell Rails about it. :) >As of now I have content from database fields showing ok, but problems with certaing .rhtml files: /views/layouts/subcribe.rhtml works fine: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <title>F?rlagets Namn</title> <%= stylesheet_link_tag ''subscribe'', :media => ''all'' %> </head> <body> <div id=''banner''> <img src="/images/logo.png" alt="Logga" height="40" width="40" border="5" /> <%= @page_title || "Prenumerationsanm?lan" %> </div> <div id=''columns''> --- but not /views/subscribe/index.rhtml: <% for product in @products %> <div class="catalogentry"> <h3><%=h(product.designation) %></h3> <%= product.commitment %> <%= product.segment %> <br/> <br/> <span class ="catalogprice"> <%= sprintf("%0.2f", product.price) %> Kr</span> <%= link_to ''Best?ll'', {:action => ''add_to_cart'', :id => product }, :class => ''addtocart'' %> <br/> </div> <div class="separator"> </div> <% end %> <%= link_to "Visa min best?llning", :action => "display_cart" %> the word ''Best?ll'' and "Visa min best?llning" becomes Best?ll etc. Per-Olof -- Posted via http://www.ruby-forum.com/.
I have now reverted to "not telling Rails about it", i.e in application.rb I don?t have any reference to character sets. In the layout I have: <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> Thirdly I made sure to save the index.rhtml (referenced as <%= @content_for_layout %> in the layout) with format UTF-8. Obviously my editor (UltraEdit) saved it as something else by default, and when I experimented the layout got saved as UTF-8 but not the index.rhtml. So, my problem solved. It was Thomas Fuchs messsage not to tel "Rails about it" that got me thinking in the right direction. Thanks everyone! Per-Olof -- Posted via http://www.ruby-forum.com/.
On the issue of international characters I (as a total newbie) wonder if the following distinction of internationalization is correct in RoR. The issue has three levels (and I found it difficult to distinguish between them in the documentation on the RoR-Wikil 1. rhtml-level, how to get UTF-8 characters to be presented correctly in a browser (view-level?) 2. database content (i.e the content in the fields of the tables in the database (controller-level?) 3. database design (meta?) level, i.e the names of tables and fields of the database (model-level?) I have solved level one in my installation, and that works for me, I don?t need table names and fields with other than english characters since we use english on the database design level. In the future I might need a solution on level 2, but I?ll tackle that when that time comes... Regards, Per-Olof -- Posted via http://www.ruby-forum.com/.
Per-Olof Hermansson wrote:> Per-Olof Hermansson wrote: >> Calle Dybedahl wrote: >>> Make everything Latin-1 instead? Rails itself is fairly >>> encoding-agnostic, as far as I''ve seen. > > That?s what I had from start. Contents are ok, but problems with the > characters in the .rhtml pages. > > Per-OlofMake sure your .rhtml files are encoded in UTF8 and not some latin-1 or macroman format... This setting is done in your editor. Textedit on mac has an option to set the encoding when you "save as..." for example. Textmate has the same. -- Posted via http://www.ruby-forum.com/.
Gazoduc wrote:> Make sure your .rhtml files are encoded in UTF8 and not some latin-1 or > macroman format... This setting is done in your editor. Textedit on mac > has an option to set the encoding when you "save as..." for example. > Textmate has the same.Yes, I am learning that the hard way, UltraEdit that I use can set "sav as...", but then it seam I cannot type in UTF8-mode (I can?t see what I type). I have posted a question on UltraEdit forum about this, but it seems that I need to fina another editor. I tried RadRails, but could not find where to set the encoding type. Per-Olof -- Posted via http://www.ruby-forum.com/.
> > I tried RadRails, but could not find where to set the encoding type. > > Per-OlofCtrl+Click a file/folder --> Properties --> Text file encoding -- Posted via http://www.ruby-forum.com/.
Gazoduc wrote:>> >> I tried RadRails, but could not find where to set the encoding type. >> >> Per-Olof > Ctrl+Click a file/folder --> Properties --> Text file encodingThanks, I tried it and it works fine. Also found where to set it in UltraEdit. But from what i have seen in Radrails I will use Radrails for working with RoR, and keep UltraEdit for working with large textfiles. Per-Olof -- Posted via http://www.ruby-forum.com/.