Forum: Ruby on Rails incompatible character encodings: ASCII-8BIT and UTF-8

Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-03-29 14:21
Hello,

I just tried to migrate one of my applications from ruby 1.8 to ruby 1.9
and get following error:
  Showing app/views/layouts/application.html.erb where line #48  raised:
  incompatible character encodings: ASCII-8BIT and UTF-8

  48:     <%= render :partial => 'layouts/menu' %>

I added "<%# coding: utf-8 %>" in application.html.erb and
layouts/_menu.rhtml but it still throws that error, anyone knows why?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2010-03-29 15:25
(Received via mailing list)
On 29 March 2010 13:21, Heinz Strunk <lists@ruby-forum.com> wrote:
> Hello,
>
> I just tried to migrate one of my applications from ruby 1.8 to ruby 1.9
> and get following error:
>  Showing app/views/layouts/application.html.erb where line #48  raised:
>  incompatible character encodings: ASCII-8BIT and UTF-8
>
>  48:     <%= render :partial => 'layouts/menu' %>
>
> I added "<%# coding: utf-8 %>" in application.html.erb and

<%# ..     %> is a comment, perhaps you meant <%-

Colin
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-03-29 16:08
No, all I found on google said I have to put it as a comment, <%- gives
a syntax error.

I just run into the same problem in two other projects. Is there a way
to set the encoding application wide?
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2010-03-29 17:06
(Received via mailing list)
On 29 March 2010 15:08, Heinz Strunk <lists@ruby-forum.com> wrote:
> No, all I found on google said I have to put it as a comment, <%- gives
> a syntax error.

You seem to have snipped the useful stuff.  How about encoding rather
than coding?  Though I am not convinced.

Colin
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-03-29 17:11
Sorry, that was a typo. Even though it's still not working.
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-03-29 17:13
In every of my 4 projects with this error it always throws it when a
special char is being displayed like ä, ö , ü, é, à etc.

It would be cool if I just need to paste some "# encoding: utf-8" or
something somewhere and it recognizes everything as utf-8, is there
anything like that I could do?
A58d6b71afc3d1f9eba3e16838639f0a?d=identicon&s=25 Gudleik Rasch (Guest)
on 2010-03-29 22:39
(Received via mailing list)
I've been struggling with the same issue a few times, and the solution
that worked for me was to use a different mysql driver: ruby-mysql

# in config/environment.rb:
config.gem 'ruby-mysql'

# or in Gemfile:
gem 'ruby-mysql'

The encoding must also be set in config/database.yml:
 adapter: mysql
 encoding: utf8
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-03-31 21:58
Gudleik Rasch wrote:
> I've been struggling with the same issue a few times, and the solution
> that worked for me was to use a different mysql driver: ruby-mysql
>
> # in config/environment.rb:
> config.gem 'ruby-mysql'
>
> # or in Gemfile:
> gem 'ruby-mysql'
>
> The encoding must also be set in config/database.yml:
>  adapter: mysql
>  encoding: utf8

Hey,

First of all thanks but I tried what you said and well...
gem install ruby-mysql
config/environment.rb: added config.gem 'ruby-mysql'
config/database.yml: added adapter: mysql, encoding: utf8

But when I start the server I get following error:
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements is deprecated and will be removed
on or after August 2010.  Use #requirement
no such file to load -- ruby-mysql
...
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
`require'Missing these required gems:
  ruby-mysql

You're running:
  ruby 1.9.1.378 at D:/ruby19/bin/ruby.exe
  rubygems at D:/ruby19/lib/ruby/gems/1.9.1

Run `rake gems:install` to install the missing gems.

I of course tried rake gems:install but it didn't help. I also tried to
just uninstall the mysql gem but that didn't work either. Any idea?
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-03 22:40
Any one knows what's wrong?
7e88b80767c518206c087d24227fa052?d=identicon&s=25 Zoran Szagaski (zoran)
on 2010-04-05 11:45
I'm ran into the same problems after switching to Ruby 1.9.1. Have you
found a solution yet?
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-05 12:38
Not yet, had to switch back to Ruby 1.8.6.

Maybe someone else has an idea?
64d174685ef89a2c7a02a1e3dbb009ae?d=identicon&s=25 Manos (Guest)
on 2010-04-05 14:15
(Received via mailing list)
If you have have hard coded strings in ruby code you should try
Mystring ="bla bla"
Mystring.force_encoding('ASCII-8BIT')
Before using it.
For database strings you should search for mysql to force encoding
(this is for db created with ruby 1.8)
Good luck
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-05 15:45
That means if I do a "db:migrate:reset" (recreate the db with Ruby 1.9)
that error would disappear?
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-05 16:18
I tried it, no it doesn't :(
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-05 16:19
FYI: I execute these commands:
db:drop
db:create
db:setup

Still same error.
68572e3ff4b162fdc6ed97a5491b5f38?d=identicon&s=25 Andre Lewis (alewis)
on 2010-04-05 18:09
> I just tried to migrate one of my applications from ruby 1.8 to ruby 1.9
> and get following error:
>   Showing app/views/layouts/application.html.erb where line #48  raised:
>   incompatible character encodings: ASCII-8BIT and UTF-8

Most likely, you are outputting content stored in your DB as UTF-8 onto
a template that is ASCII. This fix works for me:
http://gist.github.com/273741 -- drop this into
config/initializers/ruby_191_hacks.rb. I posted more about upgrading to
1.9.1 here:
http://earthcode.com/blog/2010/01/rails_on_ruby_19...
64d174685ef89a2c7a02a1e3dbb009ae?d=identicon&s=25 Manos (Guest)
on 2010-04-05 21:11
(Received via mailing list)
Are you sure you don't have hard coded strings in the partial or
strings assigned
to variables through controller?
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-06 11:49
Andre Lewis wrote:
>
> Most likely, you are outputting content stored in your DB as UTF-8 onto
> a template that is ASCII. This fix works for me:
> http://gist.github.com/273741 -- drop this into
> config/initializers/ruby_191_hacks.rb. I posted more about upgrading to
> 1.9.1 here:
> http://earthcode.com/blog/2010/01/rails_on_ruby_19...

Unfortunately not working:
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements is deprecated and will be removed
on or after August 2010.  Use #requirement
D:/ruby19/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:186:in `strip!':
can't modify frozen string (RuntimeError)
        from
D:/ruby19/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:186:in
`initialize'
        from
F:/NetBeansProjects/myproject/config/initializers/ruby_191_hacks.rb:12:in
`new'
        from
F:/NetBeansProjects/myproject/config/initializers/ruby_191_hacks.rb:12:in
`<top (required)>'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in
`load'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in
`block in load_with_new_constant_marking'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in
`new_constants_in'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in
`load_with_new_constant_marking'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:622:in
`block in load_application_initializers'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:621:in
`each'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:621:in
`load_application_initializers'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:176:in
`process'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/initializer.rb:113:in
`run'
        from F:/NetBeansProjects/myproject/config/environment.rb:10:in
`<top (required)>'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
`require'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
`block in require'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in
`new_constants_in'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in
`require'
        from
D:/ruby19/lib/ruby/gems/1.9.1/gems/rails-2.3.5/lib/commands/server.rb:84:in
`<top (required)>'
        from script/server:3:in `require'
        from script/server:3:in `<main>'
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-06 11:49
Manos wrote:
> Are you sure you don't have hard coded strings in the partial or
> strings assigned
> to variables through controller?

I'm only using I18n.t for strings and globalize2 for model translation.
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-04-06 12:07
Oh what I forgot. The icompati... error is showing on a line where I'm
using I18n.t and it would return a string with a umlaut.
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-22 23:51
Hi,

did You find a solution? I have the same problem on all of my projects.
DB in UTF8, rails in UTF8, but when it comes to partials with data with
german umlauts I get the mentioned error.

As far as I understand it's a problem with the erb rendering engine that
forces ASCII encoding.

This encoding-thing is so digusting...

Greetings
Sven
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-22 23:57
forgot to say: a workaround that works for me is to add the method
".force_encoding('utf-8')" to any variable with date from my database
eg.:

student.name.force_encoding('utf-8')

Good Night for now :-)
S.
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-23 00:08
Gudleik Rasch wrote:
> I've been struggling with the same issue a few times, and the solution
> that worked for me was to use a different mysql driver: ruby-mysql
>
> # in config/environment.rb:
> config.gem 'ruby-mysql'
>
> # or in Gemfile:
> gem 'ruby-mysql'
>
> The encoding must also be set in config/database.yml:
>  adapter: mysql
>  encoding: utf8

Still not good night ... :-)

I tried with rails 3 (rc) and this adapter ruby-mysql and now everything
works as expected!

Thanks a lot and now finally . Good Night!

S.
38a91d5029a6e2a12ec7a083234bd7db?d=identicon&s=25 Chris Mear (Guest)
on 2010-08-23 12:57
(Received via mailing list)
On 22 August 2010 23:08, Sven Koesling <lists@ruby-forum.com> wrote:
>> The encoding must also be set in config/database.yml:
>>  adapter: mysql
>>  encoding: utf8
>
> Still not good night ... :-)
>
> I tried with rails 3 (rc) and this adapter ruby-mysql and now everything
> works as expected!

As you figured out, the problem is to do with the old 'mysql' gem not
being encoding-aware for Ruby 1.9. (You're on Ruby 1.9, right?)

As an alternative to ruby-mysql, which is a little slow, you might
want to try the 'mysql2' gem, which is an updated version of the
original 'mysql' gem, and which has native extensions to hook into the
MySQL C library, making it faster.

Chris
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-23 17:52
>
> As an alternative to ruby-mysql, which is a little slow, you might
> want to try the 'mysql2' gem, which is an updated version of the
> original 'mysql' gem, and which has native extensions to hook into the
> MySQL C library, making it faster.
>
> Chris

Hello Chris,

thank You very much for this hint! I'll give it a try in my next
night-session..

greetings
Sven
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-25 19:34
>
> thank You very much for this hint! I'll give it a try in my next
> night-session..
>
> greetings
> Sven

Oh my god.........

first of all, the mysql2 gem works fine - thanks for the hint!

But there's one more thing: I have lots of notices in my rails app like
"... wurde gelöscht". But when I have one of those fckng german umlauts
in my controller I get this wonderful character encodings error message.

I'll try to solve this with a locale and let You know...

greetings
Sven
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-08-25 20:01
>
> I'll try to solve this with a locale and let You know...
>
> greetings
> Sven

hm, within a locale the german umlaute are allowed...
Ca74c4bd65a890bb31e2fc139427a8d4?d=identicon&s=25 Albert Català (albert_c)
on 2010-10-18 23:58
Hi, I began reading this post because i have the same problem:

Just start the aplicacion with new ruby 1.9.2 raises the error

"incompatible character encodings: ASCII-8BIT and UTF-8".....

But I have the problem before reading database, in the main menu when
ruby read "opción" and "menú"

Does anybody this solution, it seems easy.

thanks
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-10-19 16:39
Sven Koesling wrote in post #935706:
>
>>
>> thank You very much for this hint! I'll give it a try in my next
>> night-session..
>>
>> greetings
>> Sven
>
> Oh my god.........
>
> first of all, the mysql2 gem works fine - thanks for the hint!
>
> But there's one more thing: I have lots of notices in my rails app like
> "... wurde gelöscht". But when I have one of those fckng german umlauts
> in my controller I get this wonderful character encodings error message.

First: Display text does not belong in the controller.  Keep it in the
views (and perhaps the helpers).

Second: what is the encoding of the source file containing those
characters?

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
6d979f427102884945a84ec1080b2195?d=identicon&s=25 Sven Koesling (mcsvenster)
on 2010-10-19 20:51
Albert C. wrote in post #955265:
> Hi, I began reading this post because i have the same problem:
>
> Just start the aplicacion with new ruby 1.9.2 raises the error
>
> "incompatible character encodings: ASCII-8BIT and UTF-8".....
>
> But I have the problem before reading database, in the main menu when
> ruby read "opción" and "menú"
>
> Does anybody this solution, it seems easy.
>
> thanks

Hi Albert,

I don't understand this. Where are the words "opción" and "menú"? In the
view there should be no problem.

greetings
Sven
Ca74c4bd65a890bb31e2fc139427a8d4?d=identicon&s=25 Albert Català (albert_c)
on 2010-10-20 10:35
Hi, thanks for responding.
It's very simple, before acces any database, I have a presentation menu,
and a text in the view saying than user have to choose an option:

<div id="tit_menu">
  <p>Seleccione una opción del menú</p>
</div>

If I change "ó" with "o" and "ú" with "u" works fine.
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2010-10-20 14:21
It's not a satisfying solution but whenever I ran into this problem I
added
# Encoding: utf-8
to the top of the file causing this problem and it worked.

Would love to know how to get rid of all these comments and fix it for
real though :)
142e110e73a6fd6a97a5c1cdb20cc28e?d=identicon&s=25 Ly S. (ly_s)
on 2010-11-21 17:19
Hi,

Just for your information - switching to 'mysql2' gem solved my issue -
I was storing Chinese in my DB..

Plus, mysql2 should be the default mysql adapter of Rails 3 anyways...
2f5079cfd9c3eb2672f74e3eea760b50?d=identicon&s=25 Robert K. (robert_k16)
on 2010-11-25 14:36
Hallo, I face a similar problem, but here mentioned solutions seem to
not work.

When I try to display string with non-ascii chars from a mysql database
in form, sometimes the program stops with the 'incompatible character
encodings: ASCII-8BIT' error. This issue appears only at some fileds in
a table! Configuration of all fields is the same (varchar-string or
memo-text, encoding UTF-8).

For example:
I have record with 4 string fields, all have the same content (the same
word). When I try to display them, the 'incompatible...' error appears.
When I check their '.encoding', I get UTF-8 for three and ASCII-8BIT for
one! Sometimes, when I render this template again and again, two are
ASCII and Two UTF. Strange - not?
I dont know about any difference among these fields configuration.

Yes, .enforce-coding('utf-8') added to all instance in erb file works,
but it is not natty solution.

The same problem appears both at old project transformed from Ruby
1.8/rails 2.2 and at new project creatd in 5minutes via scaffolding in
ruby1,9,2/rails3.0.3.

The patch 'ruby_191_hacks.rb' does not work here, I got the same output
as 'Posted by Heinz Strunk (cojones) on 2010-04-06 11:49'

I have realized, that the template (erb file) must be saved in the same
coding, as the field are (i think the comment about UTF widely mentioned
above says to interpeter, that the file is in UTF coding)

My configuration:
Ruby 1.9.2, Rails 3.0.3 (3.0.1 behaves the same), mysql2 0.2.6 driver
(mysql 2.8.1 makes the same problem, mysql-ruby does not work here - it
misses an UNIX constant), both mysql2 and utf8 set in database.yml,
machine WinXP SP3.

Any idea, how to induce ActiveRecord to provide all the fields in the
UTF-8 encoding?
F23e14d75ece4788393441413c3fd549?d=identicon&s=25 Gjermund Lunder (gjelun)
on 2010-11-29 13:06
all,
Thanks for good ideas, but like for Robert K. it's not working for me
(ruby 1.9.2 and rails 3.0.3).

Robert K., check that your tables are of type = MyISAM and CHARACTER SET
utf8 in Mysql.

I get the same error as you; the problem appears almost every time, but
suddenly it works for again returning an error.

While we are waiting for a solution; how do you use encoding in the
erb-files? -> "Yes, .enforce-coding('utf-8') added to all instance in
erb file works" If you have the detail text in your file and the in
witch erb-file do I have to put this encoding I would be very thankful.

Thanks again to all.
Gjermund
developer and DBA
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-11-29 17:43
Gjermund Lunder wrote in post #964675:
> all,
> Thanks for good ideas, but like for Robert K. it's not working for me
> (ruby 1.9.2 and rails 3.0.3).
>
> Robert K., check that your tables are of type = MyISAM and CHARACTER SET
> utf8 in Mysql.

Er, why MyISAM?  That's generally a poor idea, since you don't get
transactions or referential integrity.

(Of course, using MySQL itself is IMHO a poor idea...)

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org

Sent from my iPhone
F23e14d75ece4788393441413c3fd549?d=identicon&s=25 Gjermund Lunder (gjelun)
on 2010-11-29 18:58
Because unfortunately innoDB tables don’t support full text searching of
UTF-8 encoded content. But innoDB tables are more flexible in general.
Source of information:
http://dev.mysql.com/doc/refman/5.1/en/fulltext-re... and
http://www.dotmana.com/?p=95.
This might not be relevant, but could be.

Robert K. (or others), If you do have have the exact line for the
enforce coding and in witch erb files to put it I would be happy.

PS:
I've tried <meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
(http://www.igvita.com/2007/04/11/secure-utf-8-inpu...) in the
top of my app/views/layout/application.html.erb
I thought this would force the browser to use UFT-8. But not. I'm able
to force the browser to show content after the page is read with right
click- Encoding on screen (but only i just one of the string columns
contains a special characters - strange).
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-11-29 19:10
Please quote when replying.

Gjermund Lunder wrote in post #964821:
> Because unfortunately innoDB tables don’t support full text searching of
> UTF-8 encoded content.

I know that, but I didn't think full-text searching was at issue here.
Perhaps I misread.

The fact that you have to choose is a major reason that I no longer use
or recommend MySQL.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (conradwt)
on 2010-11-29 21:32
(Received via mailing list)
On Mon, Mar 29, 2010 at 5:21 AM, Heinz Strunk <lists@ruby-forum.com>
wrote:

> layouts/_menu.rhtml but it still throws that error, anyone knows why?
>

Hey, I would recommend using Ruby 1.9.2 instead of Ruby 1.9.1.  Next,
mysql2 gems is not only faster than the ruby-mysql gem but it provides
the following benefits:

The Mysql2 gem is meant to serve the extremely common use-case of
connecting, querying and iterating on results. Some database libraries
out
there serve as direct 1:1 mappings of the already complex C APIs
available.
This one is not.

It also forces the use of UTF-8 [or binary] for the connection [and all
strings in 1.9, unless Encoding.default_internal is set then itll
convert
from UTF-8 to that encoding] and uses encoding-aware MySQL API calls
where
it can.
For more information, please see the following:

https://github.com/brianmario/mysql2

Good luck,

-Conrad

--
F23e14d75ece4788393441413c3fd549?d=identicon&s=25 Gjermund Lunder (gjelun)
on 2010-11-30 10:44
Anyone know how to add this patch?:
0001-enforced-utf-8-encoding-for-ruby-19-and-mysql-text.patch
(https://rails.lighthouseapp.com/projects/8994/tick...)

I've never applied such a pacth.

Thanks

Gjermund
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-11-30 17:32
Gjermund Lunder wrote in post #965049:
> Anyone know how to add this patch?:
> 0001-enforced-utf-8-encoding-for-ruby-19-and-mysql-text.patch
>
(https://rails.lighthouseapp.com/projects/8994/tick...)
>
> I've never applied such a pacth.

It's a standard *nix patch file.  The patch command could read it (see
its man page for more details), but the a/ and b/ file naming scheme
means that you'd probably be better off using git apply.

>
> Thanks
>
> Gjermund

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
2f5079cfd9c3eb2672f74e3eea760b50?d=identicon&s=25 Robert K. (robert_k16)
on 2010-11-30 18:22
Marnen Laibow-Koser wrote in post #965150:
> It's a standard *nix patch file.  The patch command could read it (see
> its man page for more details), but the a/ and b/ file naming scheme
> means that you'd probably be better off using git apply.

Is possible to use a Patch command also under Windows? What about Git
under Win? Is it safe to install such patch also for ROR-beginners?
Can I modify the source files manually (to exactly know, what have I
changed)?
2f5079cfd9c3eb2672f74e3eea760b50?d=identicon&s=25 Robert K. (robert_k16)
on 2010-11-30 18:27
Attachment: r4_test.zip (100 KB)
Gjermund Lunder wrote in post #964821:

> Robert K. (or others), If you do have have the exact line for the
> enforce coding and in witch erb files to put it I would be happy.

To replicate this error, call:

rails -v
> Rails 3.0.3
ruby - v
> ruby 1.9.2p0 (2010-08-18) [i386-mingw32]
Mysql version: 5.1.45-community-log

rails new r4_test -d mysql && cd r4_test
rails g scaffold post title:string content:string rem:text
rake db:create
rake db:migrate
rails s
http://localhost:3000/posts
call 'New Post'
to all three fields insert e.g. "löwe" or "tomáš"

After this I'll get:
> incompatible character encodings: UTF-8 and ASCII-8BIT
Extracted source (around line #15):
12:
13: <p>
14:   <b>Rem:</b>
15:   <%= @post.rem %>
16: </p>
17:
18:


A monkey work-around
--------------------
line 18 in "app\views\posts\index.html.erb" change:
    <td><%= post.rem.force_encoding('utf-8') %></td>

A better work-around
--------------------
1)add among the initializers:

class ActiveRecord::Base
  def force_utf
    attributes.each {|key, value| value.force_encoding('utf-8') if
value.encoding != 'utf-8' if value.kind_of?(String) }
  end
end

2)before first loading or using of an activerecord object in the
template
(here it is a Post) call .force_utf
here:
insert line 14 in "app\views\posts\index.html.erb"
 <%   post.force_utf %>

-----------------------
Changing InnoDb format of a table to Myisam does not help.
It is true, this problem does not appear with sqlite; but I have some
reasons to use MySQL.
I wonder, MySQL should be the couse of the problem - I have used the
same database type and revision and structure under 2.2.2 rails / 1.8
ruby without problems

I hope, next revision of ROR (3.0.4?) or mysql2 driver will solve this
problem.
F23e14d75ece4788393441413c3fd549?d=identicon&s=25 Gjermund Lunder (gjelun)
on 2010-12-01 10:46
Robert K. wrote in post #965170:
>
> A monkey work-around
> --------------------
> A better work-around
> --------------------

Thanks! Perfect.

I'm also waiting for a fix in 3.0.4. As you asked: Does anyone know if
patch and Git exists in windows? If no; how to apply std nix patch
files?

About mysql og not. It's religion, you know :-) I've used Oracle on
Unix/Linux through many years. I like mysql, though.
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-12-02 16:21
Gjermund Lunder wrote in post #965337:
> Robert K. wrote in post #965170:
>>
>> A monkey work-around
>> --------------------
>> A better work-around
>> --------------------
>
> Thanks! Perfect.
>
> I'm also waiting for a fix in 3.0.4. As you asked: Does anyone know if
> patch and Git exists in windows? If no; how to apply std nix patch
> files?

Git exists in Windows.  A *nix-style patch command probably does too,
but why are you torturing yourself with Windows? :)

>
> About mysql og not. It's religion, you know :-) I've used Oracle on
> Unix/Linux through many years. I like mysql, though.

SQLite (which Robert mentioned as his alternative) isn't suitable for
production.

I no longer trust MySQL, though, and I don't see why others still do --
it's got too many silly weaknesses and stupidities.  Given the choice,
I'll choose PostgreSQL every time.  Not religion, just being tripped up
one too many times by MySQL's issues.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
2f5079cfd9c3eb2672f74e3eea760b50?d=identicon&s=25 Robert K. (robert_k16)
on 2010-12-05 21:20
Hallo all,
>Marnen Laibow-Koser wrote in post #965696:
> Git exists in Windows.
Yes, but I don't know to work with it and therefore I cannot imagine,
how to update the core of rails without not to break it ):

> but why are you torturing yourself with Windows? :)
Well, most of my job I make on MS Excel tables with VBA support. Now I
am trying to move to Rails, but it does not work yet... Maybe in some
months I will be not more dependent on Bill's products (:

> I'll choose PostgreSQL every time.  Not religion, just being tripped up
> one too many times by MySQL's issues.
It is not first time I hear someone prefers the postgresql...
A good comparison is on http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL.

I decided to install a postgresql gem in my Rails to check it, but I
failed with:
"Installing pg (0.10.0) with native extensions
D:/Programs/ruby192/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue
in block in build_extensions': ERROR: Failed to build gem native
extension. (Gem::Installer::ExtensionBuildError)
D:/Programs/ruby192/bin/ruby.exe extconf.rb
checking for pg_config... no
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more"

(The same error after I ran either "gem install pg" or "bundle install")

This is to much complicated for me to solve.

Robert
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2010-12-06 22:43
Robert K. wrote in post #966327:
> Hallo all,
>>Marnen Laibow-Koser wrote in post #965696:
>> Git exists in Windows.
> Yes, but I don't know to work with it

Learn.

> and therefore I cannot imagine,
> how to update the core of rails without not to break it ):

I note that you conveniently neglected to quote my point that a
*nix-style patch tool also probably exists for Windows.  That or Git
will apply a patchfile very nicely indeed.

>
>> but why are you torturing yourself with Windows? :)
> Well, most of my job I make on MS Excel tables with VBA support. Now I
> am trying to move to Rails, but it does not work yet... Maybe in some
> months I will be not more dependent on Bill's products (:

Start now!  Use a *nix VM for Rails development.  I understand Virtual
Rails is nice.

[...]
> This is to much complicated for me to solve.

Well, stop complicating things further by using Windows!

>
> Robert

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen@marnen.org
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.