ボタンに絵文字を貼りたい
さて、jpmobile のおかげで簡単に携帯サイトを作れるのですが、昨今のソーシャルゲームをやっていても
のようなボタンをよく見ます。
なんで の絵文字を使わないんでしょうか?とっても気持ち悪かったので調べてみました。
Gemfile
vi Gemfile
@@ -28,3 +28,5 @@ # group :development, :test do # gem 'webrat' # end +gem "jpmobile", "0.1.2" +
bundler
bundle show bundle install
jpmobile を有効化
vi config/application.rb
@@ -38,5 +38,7 @@ # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] + + config.jpmobile.mobile_filter end end
controller
rails g controller top index
view
さて、いよいよ絵文字部分です。
まずは普通に絵文字を表示します。
vi app/views/top/index.html.erb

これを DoCoMo の UserAgent でアクセスして表示すると……
あははーw 外字の設定できてないや(笑) ソースから  の記述はなくなってるのでまぁちゃんと動いてるっぽいです。
続いて form の submit に貼ってみます。
<%= form_tag(:controller => "top", :action => "index") do %> <%= submit_tag "" %> <% end %>
これを表示すると、きちんと絵文字として認識されません。
ソースを眺めてみるとこういう HTML が返されています。
<form accept-charset="UTF-8" action="/top/index" method="post"><div style="margin:0;padding:0;display:inline"> <input name="authenticity_token" type="hidden" value="NtXRGo95g+0XeDQ5r9rGNXjHufo0LiXjI0YnWIDKnyU=" /></div> <input name="commit" type="submit" value="&#xE63E;" /> </form>
あ。一発で分かっちゃったかも。
さくらの VPS に登録してみた(4) checkinstall, vim, zsh
CentOS 5.5 だと vim のバージョンが古いんですね。
$ vi --version
VIM - Vi IMproved 7.0 (2006 May 7, compiled Sep 19 2009 17:22:08) Included patches: 1, 3-4, 7-9, 11, 13-17, 19-26, 29-31, 34-44, 47, 50-56, 58-64, 66-73, 75, 77-92, 94-107, 109, 202, 234-237 Modified by <bugzilla@redhat.com> Compiled by <bugzilla@redhat.com> Huge version without GUI. Features included (+) or not (-): +arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments +cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap +menu +mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm +mouse_xterm +multi_byte +multi_lang -mzscheme -netbeans_intg -osfiletype +path_extra +perl +postscript +printer +profile +python +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent -sniff +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save system vimrc file: "/etc/vimrc" user vimrc file: "$HOME/.vimrc" user exrc file: "$HOME/.exrc" fall-back for $VIM: "/usr/share/vim" Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -D_REENTRANT -D_GNU_SOURCE -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -I/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE -I/usr/include/python2.4 -pthread Linking: gcc -Wl,-E -Wl,-rpath,/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE -L/usr/local/lib -o vim -lncurses -lselinux -lacl -lgpm -Wl,-E -Wl,-rpath,/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/auto/DynaLoader/DynaLoader.a -L/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/CORE -lperl -lresolv -lutil -lc -L/usr/lib64/python2.4/config -lpython2.4 -lutil -lm -Xlinker -export-dynamic
と、このまま使うのが無理な感じに微妙なのです。
なのでソースから入れることになるんですが、パッケージ管理は捨てたくないのでまず checkinstall を入れることにします。といっても checkinstall も CentOS のリポジトリに無いのでこちらもソースから。
ソースを落としてきて
$ cd /usr/local/src $ sudo git clone http://checkinstall.izto.org/checkinstall.git $ sudo chown -R mayu:mayu checkinstall $ cd checkinstall
普通に make, make install
$ make $ sudo make install
/usr/local/sbin に入るので、まずは checkinstall 自身を rpm 化。
$ sudo /usr/local/sbin/checkinstall
聞かれる通りに答えていくと rpm ファイルができ上がるので、rpm でインストール。
$ sudo rpm -ivh /usr/src/redhat/RPMS/x86_64/checkinstall-20100916-1.x86_64.rpm
ちゃんと入ったかな?
$ yum info checkinstall
Loaded plugins: fastestmirror Installed Packages Name : checkinstall Arch : x86_64 Version : 20100916 Release : 1 Size : 94 k Repo : installed Summary : CheckInstall installations tracker, version 1.6.2 License : GPL Description: CheckInstall installations tracker, version 1.6.2 : : CheckInstall keeps track of all the files created or : modified by your installation script ("make install" : "make install_modules", "setup", etc), builds a : standard binary package and installs it in your : system giving you the ability to uninstall it with your : distribution's standard package management utilities.
はい、よくできました!
vim
まずソースを持ってきます。download : vim online によると Mercurial をオススメされているのかな?そのまま従います。
$ sudo yum install mercurial $ cd /usr/local/src $ sudo hg clone https://vim.googlecode.com/hg/ vim $ sudo chown -R mayu:mayu vim
ruby を有効にして make, checkinstall
$ cd vim $ ./configure --enable-multibyte --with-features=huge --enable-rubyinterp --disable-selinux $ make $ sudo /usr/local/sbin/checkinstall
$ sudo rpm -ivh /usr/src/redhat/RPMS/x86_64/vim-20100916-1.x86_64.rpm
ちゃんと入ったかな?
vim --version | grep ruby
-python3 +quickfix +reltime +rightleft +ruby +scrollbind +signs +smartindent
OK!
LANG
続いて .vimrc を編集しようとして日本語が通らないことに気づきました……。
$ echo $LANG
C
きゃーw /etc/sysconfig/i18n に書き込んでおきます。
sudo vi /etc/sysconfig/i18n
LANG=ja_JP.UTF-8
zsh
zsh も 4.2.6 と古いのでこちらもソースから。……そろそろ CentOS を使い続けるのに限界感じてきました。
$ sudo wget http://downloads.sourceforge.net/project/zsh/zsh-dev/4.3.10/zsh-4.3.10.tar.bz2 $ sudo tar jxf zsh-4.3.10.tar.bz2 $ sudo chown mayu:mayu zsh-4.3.10 $ cd zsh-4.3.10 $ ./configure $ make $ sudo /usr/local/sbin/checkinstall $ sudo rpm -ivh /usr/src/redhat/RPMS/x86_64/zsh-4.3.10-1.x86_64.rpm
さくらの VPS に登録してみた(4) nginx + unicorn
unicorn
$ gem install unicorn $ rvmsudo unicorn_rails -p 80
すると起動します。WEBrick とはここでお別れ。
ところで Rails3 は Rack アプリケーションなので、unicorn_rails を使う必要はありません。Rails.root で
$ unicorn
するだけでちゃんと立ち上がります。でも
- RAILS_RELATIVE_URL_ROOT を渡せる
- daemon として起動したとき、tmp/pids/unicorn.pid に pid を吐いてくれる
- tmp/cache/, tmp/pids/, tmp/sessions/, tmp/sockets/ を自動生成
と幾つか便利なところがあるので unicorn_rails を使えばいいと思います。
unicorn の config ですけど、実際にアプリを公開するときは preload_app を true にしたり worker_processes を増やしたりログ出したりとかしますけど今はいいや。起動スクリプトも特に書かず
$ unicorn_rails -D
しておしまい。デフォルトだと 8080 ポートです。
nginx
EPEL にお世話になりっぱなしですね(笑)
$ sudo yum install nginx
今まで Debian しか使ってこなかったので sites-available や sites-enabled が無いと落ち着かないんですよね。なのでデフォルトのサーバは別に移してしまって、sites-enabled を読み込むようにします。
$ sudo vi /etc/nginx/nginx.conf
--- nginx.conf.orig 2010-09-15 01:36:13.000000000 +0900 +++ nginx.conf 2010-09-15 01:51:38.000000000 +0900 @@ -62,60 +62,9 @@ keepalive_timeout 65; #gzip on; - - # - # The default server - # - server { - listen 80; - server_name _; - - #charset koi8-r; - - #access_log logs/host.access.log main; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - error_page 404 /404.html; - location = /404.html { - root /usr/share/nginx/html; - } - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} - } # Load config files from the /etc/nginx/conf.d directory include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; }
デフォルトのサーバ設定はこっちに転記。
$ sudo mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled $ sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default $ sudo vi /etc/nginx/sites-available/default
# # The default server # server { listen 80; server_name _; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
あとは demo アプリ用ですね。
$ sudo ln -s /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/demo $ sudo vi /etc/nginx/sites-available/demo
upstream demo.example.com { server 127.0.0.1:8080; } server { listen 80; server_name demo.example.com; location / { proxy_pass http://demo.example.com; allow all; } }
nginx を再起動すると、nginx + unicorn + rails3 + ruby1.9.2 + mysql が全部繋がって表示されます。
$ sudo /etc/init.d/nginx restart
あとはアプリを開発するだけですねー。さて、何を作りましょうか。
さくらの VPS に登録してみた(3) Ruby 1.9.2 + Rails 3
大事なことを忘れてました。更新 39 件もあった(>_<)
$ sudo yum update
さて、nginx + unicorn + rails3 + ruby1.9.2 + mysql の開発環境を作ろうと思います。
mysql
基本は下から。まず mysql を入れます。yum で良いよね。5.0.77 が入るみたいです。
$ sudo yum install mysql mysql-devel
設定は default-character-set だけ。他の設定値はまたアプリを作ってから変更しようと思います。VPS なのでそんなにメモリ潤沢じゃないですし。
$ sudo vi /etc/my.cnf
--- /etc/my.cnf.orig 2010-09-14 00:10:56.000000000 +0900 +++ /etc/my.cnf 2010-09-14 00:13:18.000000000 +0900 @@ -10,6 +10,14 @@ # to do so, uncomment this line: # symbolic-links=0 +default-character-set = utf8 + +[mysqldump] +default-character-set = utf8 + +[mysql] +default-character-set = utf8 + [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
サーバ起動して
sudo /etc/rc.d/init.d/mysqld start
自動起動に設定
sudo /sbin/chkconfig mysqld on
mysql のユーザ設定
パスワードなしでログインできちゃうので。
$ mysql -u root mysql
mysql> grant all PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '********'; mysql> delete from user where password = '';
git
RVM を入れるのに git, bash, curl が必須?っぽいので。bash, curl はデフォルトで入っているので git をインストール……と行きたいんですが、CentOS のリポジトリって git 入ってないんですね。EPEL から入れることにします。
$ su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm' $ sudo yum install git
rvm
こちらはドキュメント通りにさらっと。
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ) source "$HOME/.rvm/scripts/rvm"
ruby
rvm 経由で ruby を入れます。せっかくなので出たばっかりの 1.9.2 を!
……の前に。必要なライブラリを yum で入れておきます。 rvm package でも良いんですけど、なんとなく yum で。
$ sudo yum install openssl-devel readline-devel zlib-devel
続いて ruby。
$ rvm install 1.9.2 $ rvm use 1.9.2 --default
rails
$ gem install rails --no-ri --no-rdoc $ gem install mysql2 --no-ri --no-rdoc
サンプルアプリの作成
$ mkdir ~/workspaces $ cd ~/workspaces $ rails new demo -d mysql $ vi config/database.yml
development: adapter: mysql2 encoding: utf8 reconnect: false database: demo_development pool: 5 username: root password: ******** host: localhost
これまたなんとなく nifty-generators を使ってみます。画面は nifty (=かっこよい) かなぁ?(笑)
$ gem install nifty-generators --no-ri --no-rdoc $ vi Gemfile
gem 'nifty-generators'
で、scaffold。
$ rails g nifty:layout $ rails g nifty:scaffold entry title:string body:text
$ rake db:create $ rake db:migrate
iptables で 80 ポートしか空けていないので、rvmsudo して 80 ポートで webrick を起動して動作確認。
$ rvmsudo rails s -p 80
http://your.ip.address/entries/
にアクセスすると画面が出ます。
さくらの VPS に登録してみた(2)
パスワードすぐに来たので続きです。
まずはグループとユーザまわり
root のパスワードを変更しておきます。
# passwd
sudo を許可するグループと,それに属する私のユーザアカウントを追加。
# groupadd -g 3000 sudoers # useradd -u 1000 mayu # usermod -G sudoers mayu # passwd mayu
visudo には以下の記述を追加。sudoers group に属するユーザに sudo 権限を与えておきます。
# visudo
%sudoers ALL=(ALL) NOPASSWD:ALL
続いて ssh 周り
ここからは mayu でログインして作業します。
$ sudo vi /etc/ssh/sshd_config
root ログインの禁止と,パスワードログインの禁止かな。あと sshd の待ち受けポートも変更。10022 って定番すぎるかな? AllowGroups や AllowUsers は……公開鍵認証にしたし,今回は設定しないことにしました。
--- /etc/ssh/sshd_config.orig 2010-09-13 16:26:31.000000000 +0900 +++ /etc/ssh/sshd_config 2010-09-13 16:27:44.000000000 +0900 @@ -10,7 +10,7 @@ # possible, but leave them commented. Uncommented options change a # default value. -#Port 22 +Port 10022 #Protocol 2,1 Protocol 2 #AddressFamily any @@ -36,7 +36,7 @@ # Authentication: #LoginGraceTime 2m -#PermitRootLogin yes +PermitRootLogin no #StrictModes yes #MaxAuthTries 6 @@ -57,7 +57,7 @@ # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no -PasswordAuthentication yes +PasswordAuthentication no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes
で,自分のアカウントに ssh の公開鍵を登録。
$ mkdir -p ~/.ssh $ cat >> ~/.ssh/authorized_keys ssh-rsa AAAA(むにゃむにゃ ^D $ chmod 600 ~/.ssh/authorized_keys $ chmod 700 ~/.ssh
sshd を restert しておきます。
$ sudo /etc/init.d/sshd restart
iptables の編集
この辺からだんだんよく分からなくなってきました……。
たぶん外向きは全許可,内向きは 80 と 10022 だけ空けてる状態……になってると思うんだけど自信ないです。
$ vi ~/iptables.rules
*filter -A INPUT -i lo -j ACCEPT -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 10022 -j ACCEPT -A OUTPUT -j ACCEPT -A INPUT -j REJECT -A FORWARD -j REJECT COMMIT
$ sudo /sbin/iptables-restore < /home/mayu/iptables.rules
設定内容の確認
$ sudo /sbin/iptables -L
Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere icmp any ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:10022 REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- anywhere anywhere reject-with icmp-port-unreachable Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere
合ってるのかなぁ……。何が正しいのかが分からないと見ても分からないですね(>_<)
再起動しても大丈夫なように保存しておきます。
$ sudo /sbin/service iptables save
不要なサービスの停止
少しでも快適にしたいならやっとけって誰かが言ってたので。
$ sudo /sbin/chkconfig --list | grep :on
acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off lvm2-monitor 0:off 1:on 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off ntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off readahead_early 0:off 1:off 2:on 3:on 4:on 5:on 6:off readahead_later 0:off 1:off 2:off 3:off 4:off 5:on 6:off sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
この辺止めておきましょうか。たぶん要らない……と思う。
$ sudo /sbin/chkconfig acpid off $ sudo /sbin/chkconfig lvm2-monitor off $ sudo /sbin/chkconfig readahead_later off $ sudo /sbin/chkconfig sendmail off
で,再起動。ちゃんとログインできるかなー(笑)
$ sudo /sbin/shutdown -r now
さくらの VPS に登録してみた
わっほーい☆一年ぶりですね!
そろそろ自宅サーバを卒業しようかなと思ったのでさくらの VPS を使い始めることにしました。月額 980 円&銀行振り込み可能なのはいいですね。クレジットカードだと延々引き落とされそうですし。(明細見るのよく忘れるんです……。
まずは会員登録。VPS(仮想専用サーバー)|さくらインターネット - 無料お試し実施中 の「お申し込みはこちら」ボタンから会員登録に進みます。
メールアドレスや名前,住所に電話番号なんかを入れたら終了。VPS の代金の支払い方法は上述の通り銀行振り込みにしました。
確認メールですが,会員登録完了の 1 通目を読んでいたら振込先指定の 2 通目が来ます。おそらく振り込み完了後に root のパスワードを教えてもらえるんでしょう。VPS コントロールパネルのログイン画面はこんな感じです。
あぁ……銀行振り込みの場合はここで振り込み確認時間が取られるんですね。たぶんクレジットカードなら即サーバに入れるんでしょうけど。
歯がゆいけど自分のせいですねー(苦笑) 今振り込んだので続きはまた明日 (>_<)