daybreaksnow's diary

私を私と呼びたい

[Redmine]タグ付けを可能にするプラグインを入れる

Redmineのバージョン:2.4.3 (2014-02-08)
Ruby:2.0.0
Rails:3.2.16

プラグインURL:friflaj/redmine_tagging · GitHub

プラグインのインストール

HPの手順だと以下の通りだが、これは古い。(rails3だと、redmine/script/pluginは存在しない)

script/plugin install git://github.com/friflaj/redmine_tagging.git
bundle install

代わりに、redmineのインストールディレクトリで、以下を実行する。

./script/rails plugin install git://github.com/friflaj/redmine_tagging.git

ここで、以下のようなDB接続エラーが出た。

/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.15/lib/mysql2/client.rb:67:in `connect': Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)


どうやら、database.ymlのdevelopmentモードの設定を使っているので、MySQLに接続できないようだ。
開発モード用にDBをコピーし、database.ymlをdevelopment時はそちらに接続するように書き換える。

create database db_redmine_dev default character set utf8;
grant all on db_redmine_dev.* to user_redmine;
flush privileges;

mysqldump -u root -p db_redmine | mysql -u root -p db_redmine_dev

再度rails pluginを実行、正常終了。

Initialized empty Git repository in /var/lib/redmine-comp/vendor/plugins/redmine_tagging/.git/
remote: Counting objects: 74, done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 74 (delta 4), reused 53 (delta 3)
Unpacking objects: 100% (74/74), done.
From git://github.com/friflaj/redmine_tagging
 * branch            HEAD       -> FETCH_HEAD

上記をよく見ると、プラグインredmine/pluginsではなく、redmine/vendor/pluginsに展開されてしまっている。
これではプラグインとして認識されないので、redmine/pluginsに移動する

その後、redmineのインストールディレクトリで、bundle installを実行。
ここでもエラーが出た。

Updating git://github.com/Undev/rails_sql_views.git
Fetching gem metadata from https://rubygems.org/.......
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "rake":
  In snapshot (Gemfile.lock):
    rake (10.2.2)

  In Gemfile:
    rails_sql_views (>= 0) ruby depends on
      rake (~> 0.9.2) ruby

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

よく分からんがbundle updateしろと言われているので、その通りにする。


タグ利用のmigrationファイルの生成

HPの手順

rails generate acts_as_taggable_on:migration

正常終了した。

      create  db/migrate/20140408024608_acts_as_taggable_on_migration.rb
DBのマイグレーション

HPの手順。

rake db:migrate RAILS_ENV=production
rake db:migrate_plugins RAILS_ENV=production

rakeだと共通ライブラリを使ってしまうので、bundle exec rakeを使う。

一行目。

# bundle exec rake db:migrate RAILS_ENV=production
==  ActsAsTaggableOnMigration: migrating ======================================
-- create_table(:tags)
   -> 0.0106s
-- create_table(:taggings)
   -> 0.0038s
-- add_index(:taggings, :tag_id)
   -> 0.0098s
-- add_index(:taggings, [:taggable_id, :taggable_type, :context])
   -> 0.0212s
==  ActsAsTaggableOnMigration: migrated (0.0458s) =============================

二行目。

Migrating redmine_tagging (Redmine Tagging plugin)...
==  CreateViews: migrating ====================================================
-- create_view(:issue_tags, "select taggings.id, tags.name as tag, taggings.taggable_id as issue_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'Issue'")
   -> 0.0149s
-- create_view(:wiki_page_tags, "select taggings.id, tags.name as tag, taggings.taggable_id as wiki_page_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'WikiPage'")
   -> 0.0035s
==  CreateViews: migrated (0.0187s) ===========================================

==  ScrubBody: migrating ======================================================
==  ScrubBody: migrated (0.0049s) =============================================

==  RecreateViews: migrating ==================================================
-- drop_view(:issue_tags)
   -> 0.0010s
-- drop_view(:wiki_page_tags)
   -> 0.0004s
-- create_view(:issue_tags, "select taggings.id as id, tags.name as tag, taggings.taggable_id as issue_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'Issue'")
   -> 0.0021s
-- create_view(:wiki_page_tags, "select taggings.id as id, tags.name as tag, taggings.taggable_id as wiki_page_id from taggings join tags on taggings.tag_id = tags.id where taggable_type = 'WikiPage'")
   -> 0.0016s
==  RecreateViews: migrated (0.0054s) =========================================

==  FixTaggingContexts: migrating =============================================
==  FixTaggingContexts: migrated (0.0053s) ====================================

==  FixBrokenIssueAndWikiContexts: migrating ==================================
==  FixBrokenIssueAndWikiContexts: migrated (0.0022s) =========================

==  FixTagsWithBackslash: migrating ===========================================
==  FixTagsWithBackslash: migrated (0.0016s) ==================================


Note: The rake task db:migrate_plugins has been deprecated, please use the replacement version redmine:plugins:migrate
redmineの起動

手順が終わったので、httpdを再起動し、redmineにアクセス。
ここで、エラーが出てページが表示できなかった。

It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:

bundle install
If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:

Is this app supposed to be run as the apache user?
Is this app being run on the correct Ruby interpreter? Below you will see which Ruby interpreter Phusion Passenger attempted to use.
-------- The exception is as follows: -------

git://github.com/Undev/rails_sql_views.git (at master) is not yet checked out. Run `bundle install` first. (Bundler::GitError)
  /usr/local/lib/ruby/gems/2.0.0/gems/bundler-1.5.3/lib/bundler/source/git.rb:179:in `rescue in load_spec_files'

エラーメッセージでググったところ、bundle installをrootでやっていると、redmineを起動しているユーザ(apache)で使えないようだ。
参考:http://stackoverflow.com/questions/6648870/is-not-checked-out-bundle-install-does-not-fix-help

以下のように、deploymentを付けて、再度bundle installを実行する。

bundle install --deployment

httpdを再起動して、アクセスすると、正常に表示され、タグの追加も可能となった。