About chinese display

hello:
I have built a project with Instant Rails.Now only a database and a
scaffold based on a product model have finished.But when i inputted
“…/admin/list” in my browser,i found my chinese characters cound not
display normally.Then i made five steps:
1 ajusting encoding in my browser menu
2 in “C:\InstantRails\conf_files\my.ini"directory,making sure
“my.ini” file containg “[mysqld] default-character-set=utf8
[client] default-character-set=utf8” setting.
3 adding “encoding: utf8” in my “config/database.yml” file
4 making all the “.rtml"and”.rb” files saved in “utf8” way
5 deleting my database and rebuilding the database
When i made my “three” migration using “rake db:migrate”,an error
displayed in my console window saying “001_create_products.rb:14:syntax
error, unexpected kEND,expecting $end”.
How do i manage this problem?
More important,i want to know how can i make my app to display
chinese correctly.
thank you!

Guo Y. wrote:

  4 making all the ".rtml"and".rb" files saved in "utf8" way
  5 deleting my database and rebuilding the database
When i made my "three" migration using "rake db:migrate",an error

displayed in my console window saying “001_create_products.rb:14:syntax
error, unexpected kEND,expecting $end”.
How do i manage this problem?
More important,i want to know how can i make my app to display
chinese correctly.
thank you!

Like the error says you have a syntax error in your
001_create_products.rb migration. If you want us to help you find it
you’ll need to show it to us.

As for displaying Chinese characters you are almost there. You’ll
probably need something like this in the section of your pages:

Other variations on the above described here:


Michael W.

Ok,the following are all the codes in the 001_create_products.rb.

class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.column(:title, :string)
t.column(:description,:text)
t.column(:image_url,:string)
t.column(:stock,:integer)
end
end

def self.down
drop_table :products
end
end

Michael W. wrote:

Guo Y. wrote:

  4 making all the ".rtml"and".rb" files saved in "utf8" way
  5 deleting my database and rebuilding the database
When i made my "three" migration using "rake db:migrate",an error

displayed in my console window saying “001_create_products.rb:14:syntax
error, unexpected kEND,expecting $end”.
How do i manage this problem?
More important,i want to know how can i make my app to display
chinese correctly.
thank you!

Like the error says you have a syntax error in your
001_create_products.rb migration. If you want us to help you find it
you’ll need to show it to us.

As for displaying Chinese characters you are almost there. You’ll
probably need something like this in the section of your pages:

Other variations on the above described here:

Character encodings


Michael W.

Guo Y. wrote:

end

def self.down
drop_table :products
end
end

That looks okay. It ran on my setup, copy and pasting from above.

I would suggest typing it over in a new file that you create with
“script/generate migration”. If you are running a double-byte or other
non-Latin input scheme there may be something odd embedded in the file.


Michael W.

Thank you!I have done it according yours advice.But do i need to modify
the following to make chinese diplay?
2 making sure"my.ini" file containg “[mysqld]
default-character-set=utf8 [client] default-character-set=utf8” setting.
3 adding “encoding: utf8” in my
“config/database.yml” file

Michael W. wrote:

Guo Y. wrote:

end

def self.down
drop_table :products
end
end

That looks okay. It ran on my setup, copy and pasting from above.

I would suggest typing it over in a new file that you create with
“script/generate migration”. If you are running a double-byte or other
non-Latin input scheme there may be something odd embedded in the file.


Michael W.

Guo Y. wrote:

Thank you!I have done it according yours advice.But do i need to modify
the following to make chinese diplay?
2 making sure"my.ini" file containg “[mysqld]
default-character-set=utf8 [client] default-character-set=utf8” setting.
3 adding “encoding: utf8” in my
“config/database.yml” file

You do need the “encoding: utf8” line in your database.yml file.

For MySQL there’s a bunch of different ways to set the database or table
to use utf8. I don’t typically use Windows with MySQL so I’ve never
configured a my.ini file but you should be able to confirm the character
set within the mysql command line tool with “show create database
<database_name>”.

E.g. for my Rails app that can display utf8 characters I get:

±--------------------±----------------------------------------------------------------------------------------------+
| Database | Create Database
|
±--------------------±----------------------------------------------------------------------------------------------+
| topsites_production | CREATE DATABASE topsites_production /*!40100
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */ |
±--------------------±----------------------------------------------------------------------------------------------+


Michael W.

Thank you!When i use command “show create database
<database_name>”,the console window show that database’s coding is
“latin1”.Later I added line "encoding: utf8"in my
database.yml,remigrated my three migrations,then console window said:

D:\ruby\cashmere>rake db:migrate VERSION=0
(in D:/ruby/cashmere)
== AddTestData: reverting

== AddTestData: reverted (0.1400s)

== AddPrice: reverting

– remove_column(:products, :price)
-> 0.1870s
== AddPrice: reverted (0.1870s)

== CreateProducts: reverting

– drop_table(:products)
-> 0.0470s
== CreateProducts: reverted (0.0470s)

D:\ruby\cashmere>rake db:migrate
(in D:/ruby/cashmere)
== CreateProducts: migrating

– create_table(:products)
-> 0.0930s
== CreateProducts: migrated (0.0930s)

== AddPrice: migrating

– add_column(:products, :price, :integer, {:default=>0})
-> 0.1250s
== AddPrice: migrated (0.1250s)

== AddTestData: migrating

rake aborted!
Mysql::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and
(utf8_g
eneral_ci,COERCIBLE) for operation ‘=’: SELECT * FROM products WHERE
(products.t
itle = ‘白领男’) LIMIT 1

 This shows mysql setting is not right.How can i manage it?I am a

fresher to mysql.

Michael W. wrote:

Guo Y. wrote:

Thank you!I have done it according yours advice.But do i need to modify
the following to make chinese diplay?
2 making sure"my.ini" file containg “[mysqld]
default-character-set=utf8 [client] default-character-set=utf8” setting.
3 adding “encoding: utf8” in my
“config/database.yml” file

You do need the “encoding: utf8” line in your database.yml file.

For MySQL there’s a bunch of different ways to set the database or table
to use utf8. I don’t typically use Windows with MySQL so I’ve never
configured a my.ini file but you should be able to confirm the character
set within the mysql command line tool with “show create database
<database_name>”.

E.g. for my Rails app that can display utf8 characters I get:

±--------------------±----------------------------------------------------------------------------------------------+
| Database | Create Database
|
±--------------------±----------------------------------------------------------------------------------------------+
| topsites_production | CREATE DATABASE topsites_production /*!40100
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */ |
±--------------------±----------------------------------------------------------------------------------------------+


Michael W.

Guo Y. wrote:

fresher to mysql.
I do it like this inside the MySQL command line tool:

create database cashmere_development character set utf8 collate
utf8_bin;
create database cashmere_test character set utf8 collate utf8_bin;
create database cashmere_production character set utf8 collate utf8_bin;


Michael W.

Guo Y. wrote:

def self.up

end
Mysql::Error: Can’t create table ‘.\cashmere_development\products.frm’
column?If so,how do i set it in rail’migration file like
001_create_products.rb?
Thank you!

Something is messed up in your MySQL database. Google on “errno 121” for
more info. Here’s an example of what might be the problem:

http://www.jsw4.net/info/listserv_archives/mysql/03-wk07/msg00159.html


Michael W.

Thank you!But i still have to bother you!
I follow these steps to manage the chinese display.
1: use mysql command “create database cashmere_development default
character set utf8 collate utf8_bin;” to create my database that support
utf8.This step succeeds.
2: add “encoding: utf8” to the cash_development section of the
dababase.yml file.
3: create model and migration using rails command"ruby script/generate
model product",then modify the 001_create_products.rb file like this:
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.column :title,:string
t.column :description,:text
t.column :image_url,:string
t.column :stock,:integer
end
end

def self.down
drop_table :products
end
end

at last,migrate it using"rake db:migrate".Here,i got an error saying:

D:\ruby\cashmere>rake db:migrate
(in D:/ruby/cashmere)
== CreateProducts: migrating

– create_table(:products)
rake aborted!
Mysql::Error: Can’t create table ‘.\cashmere_development\products.frm’
(errno: 1
21): CREATE TABLE products (id int(11) DEFAULT NULL auto_increment
PRIMARY KEY
, title varchar(255) DEFAULT NULL, description text DEFAULT NULL,
image_url varchar(255) DEFAULT NULL, stock int(11) DEFAULT NULL) ENGINE=InnoDB

How do i manage this problem? Is that because utf8 can not be used 

for “stock” column?Should i define diffrent character set for diffrent
column?If so,how do i set it in rail’migration file like
001_create_products.rb?
Thank you!

Michael W. wrote:

Guo Y. wrote:

fresher to mysql.
I do it like this inside the MySQL command line tool:

create database cashmere_development character set utf8 collate
utf8_bin;
create database cashmere_test character set utf8 collate utf8_bin;
create database cashmere_production character set utf8 collate utf8_bin;


Michael W.

Thank you!I think i have solved this problem by dropping database in 

command line instead of deleting it manually.My page now can display
chinese,but i found a unneccesary line at top of my page
saying:ﻄ1?7!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> .Although
this is not an important flaw,I don’t know why?
It is harmful to my page appearance.
Thank you !

Michael W. wrote:

Guo Y. wrote:

def self.up

end
Mysql::Error: Can’t create table ‘.\cashmere_development\products.frm’
column?If so,how do i set it in rail’migration file like
001_create_products.rb?
Thank you!

Something is messed up in your MySQL database. Google on “errno 121” for
more info. Here’s an example of what might be the problem:

http://www.jsw4.net/info/listserv_archives/mysql/03-wk07/msg00159.html


Michael W.