続き
前回の続きから試す。
放り込んでから日本語での入力を初めて試す
ActiveRecord::StatementInvalid in WikiController#create
Mysql::Error: #HY000Incorrect string value: '\xE3\x81\x82' for column 'name' at row 1: INSERT INTO `pages` (`name`, `updated_at`, `title`, `content`, `freezeflag`) VALUES('あ', '2008-02-23 11:05:47', NULL, NULL, NULL)
あっちこっち探してみる。Ruby on RailsとMySQLで日本語(UTF-8)を使うが参考になりそうなので熟読する。
C:\Aptana IDE Beta\wiki>mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use wiki_development
Database changed
mysql> show variables like 'charcter_set%'
-> ;
Empty set (0.00 sec)mysql> show variables like 'character_set%';
- -
- +
Variable_name Value |
- -
- +
character_set_client utf8 |
character_set_connection utf8 |
character_set_database latin1 |
character_set_filesystem binary |
character_set_results utf8 |
character_set_server utf8 |
character_set_system utf8 |
character_sets_dir C:\Program Files\MySQL\MySQL Server 5.0\share\chars ets\ |
- -
- +
8 rows in set (0.00 sec)
mysql> status
- -
mysql Ver 14.12 Distrib 5.0.41, for Win32 (ia32)
Connection id: 9
Current database: wiki_development
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 1 hour 28 min 45 secThreads: 3 Questions: 85 Slow queries: 0 Opens: 21 Flush tables: 1 Open tab
les: 1 Queries per second avg: 0.016
- -
Db charactersetがlatin1になっていた。
これでNGだと信じて「データベースの文字コードを変更するには、alter databaseコマンド」を使ってみる。
mysql> alter database wiki_development default character set utf8;
Query OK, 1 row affected (0.00 sec)mysql> status
- -
mysql Ver 14.12 Distrib 5.0.41, for Win32 (ia32)
Connection id: 9
Current database: wiki_development
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 1 hour 32 min 32 secThreads: 3 Questions: 88 Slow queries: 0 Opens: 21 Flush tables: 1 Open tab
les: 0 Queries per second avg: 0.016
- -
うむ。直った!!
続いて、カラムの文字セットを確認してみる。
mysql> show create table pages;
- -
- -
- -
- +
Table Create Table
|
- -
- -
- -
- +
pages CREATE TABLE `pages` ( `id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`title` varchar(255) default NULL,
`freezeflag` tinyint(1) default NULL,
`updated_at` datetime default NULL,
`content` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
- -
- -
- -
- +
1 row in set (0.00 sec)
テーブルの作り直しが有効らしいので頑張る
C:\Aptana IDE Beta\wiki>mysql -u root -p wiki_development
mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use wiki_development
Database changed
mysql> status
- -
mysql Ver 14.12 Distrib 5.0.41, for Win32 (ia32)
Connection id: 11
Current database: wiki_development
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
TCP port: 3306
Uptime: 1 hour 36 min 41 secThreads: 3 Questions: 105 Slow queries: 0 Opens: 23 Flush tables: 1 Open ta
bles: 0 Queries per second avg: 0.018
- -
mysql> show create table pages;
- -
- -
- -
- +
Table Create Table
|
- -
- -
- -
- +
pages CREATE TABLE `pages` ( `id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`title` varchar(255) default NULL,
`freezeflag` tinyint(1) default NULL,
`updated_at` datetime default NULL,
`content` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
- -
- -
- -
- +
1 row in set (0.00 sec)
なおったよー!!!!!!!
RailsでWikiクローンを作る08
5から7までの作業の間に問題は無かったので省略。
http://tam.qmix.org/wiki/Minki08.html
Routing
URLを変更するのに使うらしい。
- 変更前:http://localhost:3000/wiki/show/ページ名
- 変更後:http://localhost:3000/show/ページ名
他のRailsアプリケーションと同居する予定なので、やらないことにする。
RailsでWikiクローンを作る09
http://tam.qmix.org/wiki/Minki09.html
課内用なので要らない気もするけど、とりあえず作ってみる。
管理画面: DBとモデル
db/create_conf.sqlを作る
#CREATE DATABASE wiki_development DEFAULT CHARACTER SET utf8; drop table if exists confs; create table confs ( id int auto_increment, site_name varchar(255) not null, author_name varchar(255), theme varchar(255), use_wikiname boolean, use_plugin boolean, primary key(id) ); insert into confs (site_name, author_name, theme, use_wikiname, use_plugin) values ('hoge hoge', '名無しさん', 'hiki', true, false);
微妙に宣言が異なる。insertのboolean型が落とし穴だった。
モデルを作る
C:\Aptana IDE Beta\wiki>ruby script/generate model Conf
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/conf.rb
create test/unit/conf_test.rb
create test/fixtures/confs.yml
exists db/migrate
create db/migrate/002_create_confs.rb
dbディレクトリにもなんだか出来上がっているけど、まぁいっか。
管理画面: コントローラとビュー
やってみる
C:\Aptana IDE Beta\wiki>ruby script/generate controller Admin basic
exists app/controllers/
exists app/helpers/
create app/views/admin
exists test/functional/
create app/controllers/admin_controller.rb
create test/functional/admin_controller_test.rb
create app/helpers/admin_helper.rb
create app/views/admin/basic.html.erb
app/controllers/admin_controller.rb
そのまんまなので省略
app/views/admin/basic.rhtml
<% @title = "基本設定" %><%= error_messages_for 'conf' %><% if flash[:notice] %>
<%= flash[:notice]%>
<% end %><% form_tag :action => 'basic' do %><% end %>
サイト名
<%= text_field 'conf', 'site_name' %>
著者名
<%= text_field 'conf', 'author_name' %>
テーマ
<%= text_field 'conf', 'theme' %>
WikiNameによるリンク機能の利用
<%= select 'conf', 'use_wikiname', [['true',true],['false',false]] %>
<%= submit_tag "Update" %>
form_tagのあたりが違う。
RailsでWikiクローンを作る10
http://tam.qmix.org/wiki/Minki10.html
動いている奴を使いまわすので利用しない
RailsでWikiクローンを作る11
http://tam.qmix.org/wiki/Minki11.html
ユーザー認証しないと閲覧できない仕掛けだけど、どーしよっかなー?
すっ飛ばす。
フィルタ
認証をまだ使わないので飛ばす。
やっぱり適用する
http://blog.codezine.jp/editor/2007/06/ruby_on_rails_1.php
って、完成したらしいが「side_menu」は作らないのかい!