/usr/local
だなんだと言われているけど、寝ている間に終わればいいやと放置したので特に何もせず。起きたら無事に終わっていたし、今使っていて何も問題ない。
ただ、UI は前のほうがいいな。なんかちゃちく見える。
左上の信号みたいなボタン3つの主張が激しくなった。
透明感のあるメタリックな感じが良かったのに、パステルなペイント風になってがっかりだ。
/usr/local
だなんだと言われているけど、寝ている間に終わればいいやと放置したので特に何もせず。
さくらVPSにログインするとアップグレードできるよって通知が出ていたので、14.04 にアップグレードしやした。
盛大にハマった....
$ do-release-upgradeいきなり容量が足りないときた。The upgrade has aborted. The upgrade needs a total of 55.6 M free space on disk '/boot'. Please free at least an additional 12.7 M of disk space on '/boot'. Empty your trash and remove temporary packages of former installations using 'sudo apt-get clean'.
/boot
以下のファイルのうち、最新バージョン以外を削除して再度実行すればOKだった。$ mv /usr/bin/erb{,.bak} $ mv /usr/bin/gem{,.bak} $ mv /usr/bin/irb{,.bak} $ mv /usr/bin/rake{,.bak} $ mv /usr/bin/rdoc{,.bak} $ mv /usr/bin/ri{,.bak} $ mv /usr/bin/ruby{,.bak} $ mv /usr/bin/testrb{,.bak} $ ln -sfn /opt/ruby/ruby-2.1.2/bin/* /usr/binようやく Ubuntu でも 1.9.3 がデフォルトになったのか。めでたい。
$ gem install passenger言われるままにインストールする。/opt/ruby/ruby-2.1.2/bin/passenger-install-apache2-module を実行 * To install Apache 2 development headers: Please install it with apt-get install apache2-threaded-dev * To install Apache Portable Runtime (APR) development headers: Please install it with apt-get install libapr1-dev * To install Apache Portable Runtime Utility (APU) development headers: Please install it with apt-get install libaprutil1-dev
$ aptitude install apache2-threaded-dev libapr1-dev libaprutil1-devpassengerモジュールをインストール。
$ passenger-install-apache2-moduleなぜかビルド出来ない。調べてみると unixd_config は ap_unixd_config にリネームされたらしいが、決定的な情報が出てこず、ハマる。悩む。apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/passenger.load: Cannot load /opt/ruby/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so into server: /opt/ruby/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so: undefined symbol: unixd_config apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/passenger.load: Cannot load /opt/ruby/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so into server: /opt/ruby/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/passenger-4.0.45/buildout/apache2/mod_passenger.so: undefined symbol: unixd_config Your Apache installation might be broken
ERR_SSL_PROTOCOL_ERROR
とか言われて接続できていないんですけどー。/etc/apache2/sites-available/default-ssl.conf
から /etc/apache2/sites-enabled/000-default-ssl.conf
とかシンボリックリンクを貼ると Redmine ではなくデフォルトページだが表示されるので、Redmine 用の設定が読み込まれていないっぽい。.conf
拡張子が必要になったらしい。$ rm /etc/apache2/sites-enabled/001-redmine $ mv /etc/apache2/sites-available/redmine{,.conf} $ ln -s /etc/apache2/sites-available/redmine.conf /etc/apache2/sites-enabled/001-redmine.conf $ service apache2 restartちゃんと読み込まれたらしい。警告が出たので、対応もした。AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/001-redmine.conf:1
You don't have permission to access / on this server.
とか言われる。今まではこれで動いとってん!/var/log/apache2/error.log
には AH01630: client denied by server configuration: /var/lib/rails/redmine/public
と出力されている。redmine.conf
にパーミッション設定をすればよさげ。<VirtualHost *:443> ServerName xxx.mkt-sys.jp:443 DocumentRoot /var/lib/rails/redmine/public <Directory /var/lib/rails/redmine/public/> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> SSLCertificateFile /etc/apache2/cert/ssl-cert.pem SSLCertificateKeyFile /etc/apache2/cert/ssl-cert.key PassengerEnabled on </VirtualHost>しかし、これでも動かない。わけわからん。
<VirtualHost *:443> ServerName xxx.mkt-sys.jp:443 DocumentRoot /var/lib/rails/redmine/public <Directory /var/lib/rails/redmine/public/> Options FollowSymLinks AllowOverride None Require all granted </Directory> SSLCertificateFile /etc/apache2/cert/ssl-cert.pem SSLCertificateKeyFile /etc/apache2/cert/ssl-cert.key PassengerEnabled on </VirtualHost>とせんとイカンらしい。これでようやくRedmineが表示された。
/usr/bin
から ImageMagick 関連のシンボリックリンクを削除した後に ImageMagick と RMagick を入れ替える。
$ aptitude install imagemagick libmagick++-dev $ cd /var/lib/rails/redmine $ bundle exec gem uninstall rmagick $ bundle installこれで、"ImageMagickのconvertコマンドが利用可能 (オプション)" は解決。
$ bundle exec rails c production irb(main):001:0> require 'RMagick'liblcms.so.1 が見つからないらしい。locate しても確かにいない。LoadError: liblcms.so.1: cannot open shared object file: No such file or directory - /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/rmagick-2.13.2/RMagick2.so from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `block in require' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/rmagick-2.13.2/lib/RMagick.rb:11:in `<top (required)>' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `block in require' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:236:in `load_dependency' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/activesupport-3.2.19/lib/active_support/dependencies.rb:251:in `require' from (irb):1 from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start' from /var/lib/rails/redmine-2.5.2/vendor/bundle/ruby/2.1.0/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
$ ldd vendor/bundle/ruby/2.1.0/gems/rmagick-2.13.2/lib/RMagick2.soなんとlinux-vdso.so.1 => (0x00007fff01ffe000) libMagickCore.so.5 => /usr/local/lib/libMagickCore.so.5 (0x00007f6be578c000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6be556e000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6be5267000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6be4ea1000) liblcms.so.1 => not found libtiff.so.4 => not found libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f6be4bfd000) libjasper.so.1 => /usr/lib/x86_64-linux-gnu/libjasper.so.1 (0x00007f6be49a6000) libjpeg.so.62 => /usr/lib/x86_64-linux-gnu/libjpeg.so.62 (0x00007f6be4780000) libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f6be455a000) libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f6be4348000) libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f6be413f000) libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f6be3f23000) libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f6be3bee000) libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f6be39dd000) libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f6be3677000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f6be345e000) libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f6be324e000) libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f6be3044000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6be2e40000) /lib64/ld-linux-x86-64.so.2 (0x00007f6be607c000) libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f6be2bea000) libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f6be29e5000) libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f6be27c5000) liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f6be25a3000) libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f6be239e000) libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f6be2198000)
liblcms.so.1
だけでなく、libtiff.so.4
も見つからないらしい。おろろーん。lrwxrwxrwx 1 root root 17 Jan 16 2014 /usr/lib/x86_64-linux-gnu/liblcms2.so -> liblcms2.so.2.0.5 lrwxrwxrwx 1 root root 17 Jan 16 2014 /usr/lib/x86_64-linux-gnu/liblcms2.so.2 -> liblcms2.so.2.0.5 -rw-r--r-- 1 root root 346928 Jan 16 2014 /usr/lib/x86_64-linux-gnu/liblcms2.so.2.0.5 # 省略 lrwxrwxrwx 1 root root 16 May 6 04:39 /usr/lib/x86_64-linux-gnu/libtiff.so -> libtiff.so.5.2.0 lrwxrwxrwx 1 root root 16 May 6 04:39 /usr/lib/x86_64-linux-gnu/libtiff.so.5 -> libtiff.so.5.2.0 -rw-r--r-- 1 root root 467208 May 6 04:39 /usr/lib/x86_64-linux-gnu/libtiff.so.5.2.0ライブラリのファイルもあるので、多少バージョンが違うかもしれないが強引にこれらにリンクさせてみる。
$ cd /usr/lib/x86_64-linux-gnu/ $ ln -s liblcms2.so liblcms.so.1 $ ln -s libtiff.so.5 libtiff.so.4Redmine を再起動して確認してみると、"ImageMagickのconvertコマンドが利用可能 (オプション)" もOKマークに変わっている。
$ aptitude install fonts-ipaexfont $ vim /var/lib/rails/redmine/config/configration.yml #=> rmagick_font_path に /usr/share/fonts/truetype/fonts-japanese-gothic.ttf を指定するとすんなり PNG でも日本語が表示された。
ActiveRecord::Base#attribute_names
で取得できるけど、has_many
などで定義された属性名は取得できない。ActiveRecord::Base#reflections
経由で取得できる。
ActiveRecord::Base#attribute_names
は文字列の配列を返すけど、こっちはシンボルの配列を返す。
まあ、普通に考えたら 2 かな?というわけで、空コミットするお仕事に戻ります。
rake routes FILL_NAME=yes
と呼び出すと、従来は
blog_posts GET /blogs/:blog_id/posts(.:format) posts#index POST /blogs/:blog_id/posts(.:format) posts#create new_blog_post GET /blogs/:blog_id/posts/new(.:format) posts#new edit_blog_post GET /blogs/:blog_id/posts/:id/edit(.:format) posts#edit blog_post GET /blogs/:blog_id/posts/:id(.:format) posts#show PUT /blogs/:blog_id/posts/:id(.:format) posts#update DELETE /blogs/:blog_id/posts/:id(.:format) posts#destroy blogs GET /blogs(.:format) blogs#index POST /blogs(.:format) blogs#create new_blog GET /blogs/new(.:format) blogs#new edit_blog GET /blogs/:id/edit(.:format) blogs#edit blog GET /blogs/:id(.:format) blogs#show PUT /blogs/:id(.:format) blogs#update DELETE /blogs/:id(.:format) blogs#destroyこうだった
rake routes
の結果が、
blog_posts GET /blogs/:blog_id/posts(.:format) posts#index blog_posts POST /blogs/:blog_id/posts(.:format) posts#create new_blog_post GET /blogs/:blog_id/posts/new(.:format) posts#new edit_blog_post GET /blogs/:blog_id/posts/:id/edit(.:format) posts#edit blog_post GET /blogs/:blog_id/posts/:id(.:format) posts#show blog_post PUT /blogs/:blog_id/posts/:id(.:format) posts#update blog_post DELETE /blogs/:blog_id/posts/:id(.:format) posts#destroy blogs GET /blogs(.:format) blogs#index blogs POST /blogs(.:format) blogs#create new_blog GET /blogs/new(.:format) blogs#new edit_blog GET /blogs/:id/edit(.:format) blogs#edit blog GET /blogs/:id(.:format) blogs#show blog PUT /blogs/:id(.:format) blogs#update blog DELETE /blogs/:id(.:format) blogs#destroyこうなります。
% rake routes | peco | awk '{print $1}' | pbcopyとかできたら便利じゃないですかね?
rake routes
だと名前があったりなかったりで欲しいものが取れないので、こんな gem を作りました。rake routes
はもっさりなので
% rake routes FILL_NAME=yes > .routesってあらかじめしておいて、
% cat .routes | peco | awk '{print $1}' | pbcopyってところですかね。
proutes
として .zshrc に登録しました。% cat .routes | peco | awk '{print $1}' | tr -d '\n' | pbcopy
rake routes
にないの?って思ってコード読んでたら、こんなの発見した。
rake routes CONTROLLER=books とすれば books_controller に関する routes だけが取れる。知らなかった。パイプ使って grep してた #rails
— pinzolo (@pinzolo) 2014, 8月 13
いや〜知らんかった。
locales/ja.yml
には ActiveModel の設定は入っていないので、プラグインの locales/ja.yml
に書くことになる。locales/ja.yml
から ActiveRecord 用の設定をコピーしてくることになりがち。
こんな感じに。ActiveModel::Model
を使うだろうから、サンプルコードはずいぶん変わると思います。activemodel.errors.messages.xxx
な i18n のキーを my_model.errors.messages.xxx
とかにしたかった。i18n_scope
をオーバーライドしてやるんだけど、全モデルクラスに書くのは嫌なので、インクルードするだけの共通モジュールを書くことに。
ActiveSupport::Concern
は ClassMethods
モジュールを反映させてから included
のブロックを実行するので、再度デフォルトで上書きしてしまう。
alias_method_chain
を使うなどして extend ActiveModel::Translation
の後にオーバーライドしてやればいい。
has_one
のサンプルとして、備考のモデルで作ってみた。note
属性で値を直接やりとりしたかったのでこんな風に。xxx_type
と xxx_id
は Rails に任せる。自分では処理しない。t.references :taggable, polymorphic: true
とするサンプルが多いけど、null が入ることは設計上ありえないんだから null: false
を付けておいたほうがいいと思う。save_note
では保存のみ実行しているけど、note_store.note
が nil の場合はデータサイズ的なことを考えると note_store.destroy
としてもいいと思う。(集約されるテーブルなので)
まあサンプルなのでシンプルにした。
load_path
での優先度が高く、tail -f pinzo.log: Redmineのプラグインで既存の文言を上書きする みたいなことをしないと、文言を上書きできませんでした。load_path
に登録されるため、特に何もせずに上書きされるようになっています。I18n.load_path
でなく Rails.application.config.i18n.load_path
に追加すると。なるほど