Hello, I have in my db a register what have special characters, and when
I try to put on my form to edit this values, this happens:
incompatible character encodings: UTF-8 and ASCII-8BIT
Extracted source (around line #4 ):
1: <%= form_for :group, :url => { :action => “update” } do |f| %>
2: <%= utf8_enforcer_tag %>
3: Nome do grupo <%= f.text_field :name %>
4: Descrição <%= f.text_area :description, :cols => 60,
:rows => 6 %>
5: <%= f.submit “Editar grupo” %>
6: <% end %>
In my database.yml
development:
adapter: mysql
enconding: utf8
database: mailler_development
reconect: false
username: mailler
password:
pool: 5
timeout: 5000
In my list action, I put utf8_encoding( “utf-8” ) to works, but I was
searching and I don’t find nothing for form_for.
thank you
Hi!
I found a typo:
enconding: utf8
Change for:
encoding: utf8
Best Regards,
Everaldo
On Tue, Feb 7, 2012 at 12:21 AM, Felipe Pieretti U. <
lipe_pe
February 8, 2012, 12:10am
3
Ok, I put the encoding: utf8
development:
adapter: mysql
encoding: utf8
database: mailler_development
reconect: false
username: mailler
password:
pool: 5
timeout: 5000
so my list.html.erb when I have this line of code
<%= g.description.force_encoding( "utf-8" ) %>
so this was the text
Novamente, nenhuma descrição
But when I change,
<%= g.description %> , shows again the error
incompatible character encodings: UTF-8 and ASCII-8BIT
Extracted source (around line #16 ):
13: <tr style=“background-color: <%= cycle( “#EEE ”, “#DDD ” ) %>”>
14:
<%= g.id %>
15:
<%= g.name %>
16:
<%= g.description %>
17:
18: <%= link_to “Editar”, { :action => “edit”, :id => g.id } %>
19: <%= link_to “Deletar”, { :action => “destroy”, :id => g.id
}, :class => “delete”, :confirm => “Tem certeza que deseja deletar
‘#{g.name}’ ?” %>
Thank you
lipe_pe
February 8, 2012, 10:22am
4
Hi!
Try to follow Jefrey tip. Because he said that mysql adapter returns
ASCII-8bit.
You must use
adapter: mysql2
Regards,
Everaldo
On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti U. <
Everaldo G. wrote in post #1044692:
Hi!
Try to follow Jefrey tip. Because he said that mysql adapter returns
ASCII-8bit.
You must use
adapter: mysql2
Regards,
Everaldo
On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti U. <
I tried, but was the same error.
I’m sorry, I don’t have more ideas to solve this.
Are you brazilian, right?
Why don’t you try the brazilian mail list? [email protected]
I suppose someone there know how to solve this issue.
Regards,
Everaldo
On Wed, Feb 8, 2012 at 1:34 PM, Felipe Pieretti U. <
Quoting Felipe Pieretti U. [email protected] :
Regards,
Everaldo
On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti U. <
I tried, but was the same error.
In the Rails console, pick a model, I use Item here, try this, and show
us the
result.
i = Item.first
i.title # any string field will do
i.title.encoding
The desired value is:
=> #Encoding:UTF-8
A couple of other things, I assume you are using Ruby 1.9, correct? And
did
you restart your server after changing database.yml?
Jeffrey
Quoting Felipe Pieretti U. [email protected] :
4: Descrio <%= f.text_area :description, :cols => 60,
reconect: false
username: mailler
password:
pool: 5
timeout: 5000
In my list action, I put utf8_encoding( “utf-8” ) to works, but I was
searching and I don’t find nothing for form_for.
Try the mysql2 adapter. The mysql adapter always returns ASCII-8BIT
strings,
even if MySQL is using UTF8 encoding.
HTH,
Jeffrey
lipe_pe
February 8, 2012, 11:34pm
9
Jeffrey L. Taylor wrote in post #1044767:
Quoting Felipe Pieretti U. [email protected] :
Regards,
Everaldo
On Tue, Feb 7, 2012 at 9:10 PM, Felipe Pieretti U. <
I tried, but was the same error.
In the Rails console, pick a model, I use Item here, try this, and show
us the
result.
i = Item.first
i.title # any string field will do
i.title.encoding
The desired value is:
=> #Encoding:UTF-8
A couple of other things, I assume you are using Ruby 1.9, correct? And
did
you restart your server after changing database.yml?
Jeffrey
1.9.3-p0 :003 > group = Group.first
Group Load (0.8ms) SELECT groups
.* FROM groups
LIMIT 1
=> #<Group id: 1, name: “Felipe”, description: “ahsidaus”, created_at:
“2012-02-08 22:32:26”, updated_at: “2012-02-08 22:32:26”>
1.9.3-p0 :004 > group.description
=> “ahsidaus”
1.9.3-p0 :005 > group.description.encoding
=> #Encoding:ASCII-8BIT
My encoding is different…
lipe_pe
February 14, 2012, 1:59am
10
I resolved this problem, after re install my ubuntu, and start another
project, I got the same error, so I put mysql2 as adapter and restart my
server.
Thank you.
lipe_pe
February 9, 2012, 2:56am
11
Quoting Felipe Pieretti U. [email protected] :
In the Rails console, pick a model, I use Item here, try this, and show
1.9.3-p0 :004 > group.description
=> “ahsidaus”
1.9.3-p0 :005 > group.description.encoding
=> #Encoding:ASCII-8BIT
My encoding is different…
This is your problem. The ASCII-8BIT string from the database are
conflicting
with UTF-8 strings in your views. Are you sure you are using mysql2?
From
the Rails console:
require ‘active_record’
Group.first
Mysql2::VERSION
=> “0.3.11”
“0.3.11” is the version of Mysql2 on my system. If it is not defined,
try
Mysql::VERSION. Presumably that will be defined. You will have to
figure out
why the wrong gem is used. At the command line “gem list mysql” will
tell
which are installed. Double check config/database.yml for “adapter:
mysql2”.
HTH,
Jeffrey