Ruby 1.9.3 encoding - ruby-on-rails

I was using ruby 1.8.7 and rails 3.2.11 for more than year and I developed my application using it, when I upgraded my ruby version to 1.9.3 these issue raised
incompatible character encodings: UTF-8 and ASCII-8BIT on my application.js file
I tried many solutions but all fails any body can help me ?

In Ruby 1.8, strings weren't encoded. In 1.9.3, you need to say what character set encoding your string is using. The default is ASCII, which is a problem, as you can't add differently encoded strings together.
For more information, look here:
http://blog.grayproductions.net/articles/ruby_19s_string
To fix it, make sure your strings and files are all using UTF 8 (or whatever you want) encoding, and your database has the right types.

Related

Special characters in ruby

Can any one suggest me any gem or a way to solve the special characters issue occurring in ruby 1.8.7 and rails 3.2.13.
I want to replace the special characters instead of removing.
I have tired using iconv gem. It works for some special characters alone.
Thanks..

incompatible character encodings utf-8 and windows-1251, installing ruby, ruby on rails

I don't know much about this stuff, help me, please. I was installing ruby railsinstaller-windows
on step 9 there was a problem
What should I do? I need a good explanation.
I guess that happens because the path where you are installing Ruby, contains non-ASCII characters (i.e. your username, try to rename it).

Why does Rails 3 pitch a fit about UTF-8 character encoding?

I just started work on a new Rails app, using the bright and shiny new version of Rails, 3.2.1. Previously, I had only used up to version 3.0.9. Before I describe my error, let it be known that I am using Ruby version ruby 1.9.2p290 (2011-07-09) [i386-mingw32] on Windows 7 32-bit. I have not changed my version of Ruby recently. I am using Notepad++ v5.9.3 and haven't (on purpose) changed any default settings.
When I ran my new app for the first time, I got an odd message:
ActionView::WrongEncodingError in Index#index
Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template:
# encoding: <name of correct encoding>.
I do not understand why I am getting this error all of a sudden. Is it part of changes made to Rails 3.2.1? It is easily fixed by going into Notepad++ and using the Encoding menu option "Convert to UTF-8" but, like I said, I've never had to do this before.
The other odd thing is that even the files that Rails generates are generated with ANSI encoding when I use a generator. Overall, I'm confused and I want to make sure that I'm using good programming practices.
Is it part of changes made to Rails 3.2.1? It is easily fixed by going into Notepad++ and using the Encoding menu option "Convert to UTF-8" but, like I said, I've never had to do this before.
Yes. Rails 3.0+ (I think) requires all templates to be saved in UTF-8 encoding. You need to save the file as UTF-8. If that still doesn't work, set the encoding explicitly by adding on the first line of your .rb files the following:
# encoding: utf-8
Add this to the first line of your .erb templates:
<%# encoding: utf-8 %>
See this related question, and this similar problem. Sounds to me like your editor's encoding settings changed since you originally created the files.
The other odd thing is that even the files that Rails generates are generated with ANSI encoding when I use a generator. Overall, I'm confused and I want to make sure that I'm using good programming practices.
That is quite odd, and I'm not sure I have a good suggestion for that one, other then trying to add Encoding.default_external = "UTF-8" to your config.ru and config/environment.rb files.
I had tried the encoding: utf-8 method without luck, but I resolved the issue when I changed the encoding using Notepad++. Thanks!

Does jruby 1.6.3 in 1.9.2 compatibility mode works with rails 2.3.11? Meaning did somebody tried that?

We are using jruby 1.6.x and we would like to switch to 1.9 mode because of UTF8 support. However, we don't want to upgrade rails from 2.3.8/2.3.11 to rails 3.
I tried to upgrade a Rails 2.3 application first to ruby 1.9.3. There were all kind of utf8-related problems. Some of them you can fix easily, by putting a utf8 header in the file, but some of the problems occur only in special conditions, for example when an error message is constructed from different parts somewhere deep in the rails stack, an one part was ascii, the other utf8.
When I investigated the problems I found other have also different kind of utf8 problems.
So it easier to go first to rails 3.0 and then to ruby 1.9

Rails 2.3.5, Ruby 1.9, SQLite 3 incompatible character encodings: UTF-8 and ASCII-8BIT

I know that question with same title has been asked almost 6 month ago.
I have Googled for this problem and I have not found any working solution.
Has there been any fixes for this very critical problem?
I need to get my website running ASAP. Just to get the site up and running I'm even ready to add utf8 conversion methods to all my variables or risk to upgrade to Rails 3 beta
Thank You in advance!
Re the reason this was happening, here is a link to a similar question that was asked more recently than yours together with a response:
ruby 1.9 + sinatra incompatible character encodings: ASCII-8BIT and UTF-8
Check out this excellent blog post for an overview of the underlying problem and some possible solutions:
http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/

Resources