機能 #40
完了Redmine 3.0でglossary pluginを動くようにする
100%
説明
Redmine 3.0にglossaryプラグイン(用語集)を入れたらエラーで動かないので、原因を調査し、動作するための修正を見出す。
終了条件:動作するための修正を見出す。動作するglossaryプラグインを見つける。あきらめる。
エラー再現手順
- 次のリポジトリを
/var/lib/redmine/plugins/
に展開
https://github.com/maxrossello/redmine_glossary.git - Unicorn再起動→起動失敗
エラー内容
/var/lib/redmine/log/unicorn.stdout.log
よりAn error occurred while loading the routes definition of redmine_glossary plugin (/var/lib/redmine-3.0.0/plugins/redmine_glossary/config/routes.rb): You should not use the `match` method in your router without specifying an HTTP method. If you want to expose your action to both GET and POST, add `via: [:get, :post]` option. If you want to expose your action to GET, use `get` in the router: Instead of: match "controller#action"
高橋 徹 さんが約10年前に更新
- ステータス を 新規 から 進行中 に変更
- 進捗率 を 0 から 50 に変更
Redmine起動エラー(routes関連)原因の調査¶
Rails 4.xからは、
- リソースベースのルーティングが推奨、matchメソッドによるルーティングも可能。
- viaオプションなしのmatchメソッドは禁止
となっているそうです。
glossaryプラグインのルーティング設定(config/routes.rb
)は、viaオプションなしのmatchメソッドが指定されているためエラーになっています。
そこで、via指定を追加するのですが、HTTPメソッドの何を指定するのか設計意図を汲み取る必要があり、glossaryプラグインの解析が必要なので今回はRedmine 2.6ベースでのglossaryのルーティング設定をrake routesで確認し、それに一致するような修正をしてみます。
Redmine 2.6ベースでのglossaryプラグインのルーティング設定
redmine$ bundle exec rake routes RAILS_ENV=production|grep glossary GET|POST|PUT /glossary_styles/:action(.:format) glossary_styles#:action GET /projects/:project_id/glossary(.:format) glossary#index GET /projects/:project_id/glossary/new(.:format) glossary#new GET|POST /projects/:project_id/glossary/edit(.:format) glossary#edit GET|POST /projects/:project_id/glossary/:id/edit(.:format) glossary#edit {:id=>/\d+/} /projects/:project_id/glossary/:id/:action(.:format) glossary#:action {:id=>/\d+/} GET /projects/:project_id/glossary/:id(.:format) glossary#show {:id=>/\d+/} DELETE /projects/:project_id/glossary/destroy(.:format) glossary#destroy /projects/:project_id/glossary/:action(.:format) glossary#:action /projects/:project_id/term_categories(.:format) term_categories#index DELETE /projects/:project_id/term_categories/destroy(.:format) term_categories#destroy POST /projects/:project_id/term_categories/change_order(.:format) term_categories#change_order /projects/:project_id/term_categories/:action(.:format) term_categories#:action /projects/:project_id/term_categories/:id/:action(.:format) term_categories#:action {:id=>/\d+/} redmine$
glossaryプラグインのconfig/routes.rb
で、matchメソッドにviaが指定されていないのは次です。
match 'projects/:project_id/glossary/:id/:action', :to => 'glossary', :id => /\d+/ match 'projects/:project_id/glossary/:action', :to => 'glossary' match 'projects/:project_id/term_categories', :to => 'term_categories#index' match 'projects/:project_id/term_categories/:action', :to => 'term_categories' match 'projects/:project_id/term_categories/:id/:action', :to => 'term_categories', :id => /\d+/
とりあえず、:viaオプションで、すべてを指定します(GET, POST, DELETEなどのどれを指定するか不明なため)。
- match 'projects/:project_id/glossary/:id/:action', :to => 'glossary', :id => /\d+/
+ match 'projects/:project_id/glossary/:id/:action', :to => 'glossary', :id => /\d+/, :via => :all
- match 'projects/:project_id/glossary/:action', :to => 'glossary'
+ match 'projects/:project_id/glossary/:action', :to => 'glossary', :via => :all
- match 'projects/:project_id/term_categories', :to => 'term_categories#index'
+ match 'projects/:project_id/term_categories', :to => 'term_categories#index', :via => :all
- match 'projects/:project_id/term_categories/:action', :to => 'term_categories'
+ match 'projects/:project_id/term_categories/:action', :to => 'term_categories', :via => :all
- match 'projects/:project_id/term_categories/:id/:action', :to => 'term_categories', :id => /\d+/
+ match 'projects/:project_id/term_categories/:id/:action', :to => 'term_categories', :id => /\d+/, :via => :all
Redmineを起動します。
# service unicorn start
起動はしました。[管理] > [プラグイン] > Redmine Glossary Pluginの[設定]欄をクリックするとInternal Errorとなってしまいました。
production.logを見ると
Started GET "/settings/plugin/redmine_glossary" for 127.0.0.1 at 2015-03-21 15:36:32 +0900 Processing by SettingsController#plugin as HTML Parameters: {"id"=>"redmine_glossary"} Current user: admin (id=1) Rendered plugins/redmine_glossary/app/views/settings/_glossary_settings.html.erb (7.7ms) Rendered settings/plugin.html.erb within layouts/admin (10.2ms) Completed 500 Internal Server Error in 22ms ActionView::Template::Error (Unknown key: :include. Valid keys are: :columns, :project_key, :date_column, :permission, :scope, :preload): 1: 2: <h2> <%= t('label_hide_item') %> </h2> 3: <table> 4: <% for item in Term.hidable_params %> 5: <% name = "hide_item_#{item}" %> 6: <tr><td> 7: <%= check_box_tag("settings[#{name}]", 1, @settings[name]) %> lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:37:in `acts_as_searchable' app/views/settings/plugin.html.erb:6:in `block in _app_views_settings_plugin_html_erb__4392166733853170509_47999300' app/views/settings/plugin.html.erb:4:in `_app_views_settings_plugin_html_erb__4392166733853170509_47999300'
となっています。
高橋 徹 さんが約10年前に更新
プラグインの設定でInternal Error(acts_as_searchable.rb)の原因調査¶
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
の@def acts_as_searchable(options = {}) の処理
return if self.included_modules.include?(Redmine::Acts::Searchable::InstanceMethods) options.assert_valid_keys(:columns, :project_key, :date_column, :permission, :scope, :preload)
と、確かにキー:includeが指定されていればassertが失敗するようになっています。
Glossaryプラグインの中で、:include
を使用している箇所は
app/model/term.rb
acts_as_searchable :columns => ["#{table_name}.name", "#{table_name}.description"], :include => [:project]
です。これがエラーになっています。app/models/term.rb
を修正してみます。
acts_as_searchable :columns => ["#{table_name}.name", "#{table_name}.description"],
- :include => [:project]
+ :project_key => [:project]
Redmineを再起動したところ、[管理] > [プラグイン] > Redmine Glossary Pluginの[設定]欄をクリックすると非表示設定画面が表示されました。
高橋 徹 さんが約10年前に更新
プロジェクトの設定で用語集を有効にしてタブをクリックしたらPage not found¶
プロジェクトの[設定] > [モジュール]で[用語集]にチェックを付けるとプロジェクトメニューに[用語集]が追加されました。
プロジェクトメニューの[用語集]をクリックすると、Page not foundエラーとなってしまいました。
ログを見ると、次のエラーメッセージが記録されています。
Started GET "/projects/newfeature300/glossary" for 127.0.0.1 at 2015-03-21 17:14:06 +0900 Processing by GlossaryController#index as HTML Parameters: {"project_id"=>"newfeature300"} Current user: admin (id=1) Completed 404 Not Found in 14ms ActiveRecord::RecordNotFound (Couldn't find all GlossaryStyles with 'id': (first, {:conditions=>"user_id = 1"}) (found 0 results, but was looking for 2)): vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:336:in `raise_record_not_found_exception!' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:479:in `find_some' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:438:in `find_with_ids' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:71:in `find' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:3:in `find' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/core.rb:128:in `find' plugins/redmine_glossary/app/helpers/glossary_styles_helper.rb:12:in `retrieve_glossary_style' vendor/bundler/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:427:in `block in make_lambda' :(後略)
app/helpers/glossary_styles_helper.rb
の12行目を見ると
@glossary_style= GlossaryStyle.find(:first, :conditions => "user_id = #{User.current.id}")
となっています。ここで、MySQLのデータベースでglossary_stylesテーブルを調べると0レコード(空)でした。
ちなみに正常動作していると見えるRedmine 2.6の方も、glossary_stylesテーブルは0レコードでした。
Rails 3までは、この「<モデル>.find(:first, [オプション])」で、テーブルの先頭行(オプション指定があればその条件での)を1レコード取得しますが、Rails 4では非推奨となっています。
また、この式は、レコードが0件でもRecordNotFound例外を出さずnilを返すとされていますが、上述エラーログのとおりRecordNotFound例外を出しています。
そこで、app/helpers/glossary_style_helper.rb
を修正します。Rail 4ではfind_byでハッシュを渡すとnilを返すようなので、次のように修正します。
- @glossary_style= GlossaryStyle.find(:first, :conditions => "user_id = #{User.current.id}")
+ @glossary_style= GlossaryStyle.find_by(:user_id => User.current.id)
Redmine再起動してプロジェクトメニューの[用語集]をクリックすると、エラー発生箇所が変化しました。
Started GET "/projects/newfeature300/glossary" for 127.0.0.1 at 2015-03-21 18:28:48 +0900 Processing by GlossaryController#index as HTML Parameters: {"project_id"=>"newfeature300"} Current user: admin (id=1) WARNING: Can't mass-assign protected attributes for GlossaryStyle: groupby Completed 404 Not Found in 111ms ActiveRecord::RecordNotFound (Couldn't find all Terms with 'id': (all, {:conditions=>["project_id = 1", {}]}) (fou nd 0 results, but was looking for 2)): vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:336:in `raise_rec ord_not_found_exception!' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:479:in `find_some ' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:438:in `find_with_ids' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:71:in `find' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:3:in `find' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/core.rb:128:in `find' plugins/redmine_glossary/app/controllers/glossary_controller.rb:354:in `find_terms' plugins/redmine_glossary/app/controllers/glossary_controller.rb:27:in `index'
app/controllers/glossary_controller.rb
の354行目は、
terms = Term.find(:all, :conditions => [query_str, symbols])
これもRails 4で非推奨なハッシュを使うfinder APIを使っているので変更してみます。
- terms = Term.find(:all, :conditions => [query_str, symbols])
+ terms = Term.where(query_str, symbols)
Redmine再起動してプロジェクトメニューの[用語集]をクリックすると、エラー発生箇所が変化しました。
ActiveRecord::RecordNotFound (Couldn't find all TermCategories with 'id': (all, {:conditions=>"project_id = 1"}) (found 0 results, but was looking for 2)): : plugins/redmine_glossary/app/helpers/glossary_styles_helper.rb:101:in `seach_category_options' :
app/helpers/glossary_styles_helper.rb
の101行目は
options += break_categories(TermCategory.find(:all, :conditions => querystr)).sort.uniq
これも同じパターンなので、
- options += break_categories(TermCategory.find(:all, :conditions => querystr)).sort.uniq
+ options += break_categories(TermCategory.where(querystr)).sort.uniq
Redmine再起動してプロジェクトメニューの[用語集]をクリックすると、エラー発生箇所が変化しました。
ActiveRecord::RecordNotFound (Couldn't find all Terms with 'id': (first, {:conditions=>"project_id = 1"}) (found 0 results, but was looking for 2)): vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/finder_methods.rb:336:in `raise_record_not_found_exception!' : plugins/redmine_glossary/app/views/glossary/_sidebar.html.erb:14:in `_plugins_redmine_glossary_app_views_glossary__sidebar_html_erb__1700419666613835256_42932460' :
これも前の修正と同じパターンなので、
-<% if (Term.find(:first, :conditions => "project_id = #{@project.id}")) %>
+<% if (Term.find_by(:project_id => @project.id)) %>
ここでとりあえず表示されるようになりました。
高橋 徹 さんが約10年前に更新
用語の追加をクリックしたらPage not foundエラー¶
先に、プロジェクトの[用語集]タブをクリックしたら表示されるようにしました。
今度は、[用語の追加]をクリックしたらエラーになる問題の修正です。
ActiveRecord::RecordNotFound (Couldn't find all TermCategories with 'id': (all, {:conditions=>"project_id = 1", :order=>"position"}) (found 0 results, but was looking for 2)): : plugins/redmine_glossary/app/controllers/glossary_controller.rb:70:in `new' :
該当箇所は次です。
@term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position")
- @term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position"
+ @term_categories = TermCategory.where(:project_id => @project.id).order(:position)
これで、新しい用語の登録画面が表示された。
高橋 徹 さんが約10年前に更新
用語の追加で項目を入力して[作成]を押したらPage not foundエラー¶
ActiveRecord::RecordNotFound (Couldn't find all Projects with 'id': (first, {:conditions=>"projects.id = 1"}) (found 0 results, but was looking for 2)): app/models/project.rb:296:in `find'
原因箇所がわからないので、今までのパターンでGlossary Plaginのコードにあるfindを片っ端から修正してみたところ、エラーが出なくなった。
高橋 徹 さんが約10年前に更新
用語の追加画面で新しいカテゴリをクリックし名称を入力して作成すると「名称を入力してください」エラー¶
ログを見ると、
Started POST "/projects/newfeature300/glossary/add_term_category" for 127.0.0.1 at 2015-03-21 23:05:01 +0900 Processing by GlossaryController#add_term_category as HTML Parameters: {"utf8"=>"?", "authenticity_token"=>"7YPrCoDOE7aWIkz2pOdOoTuC3J5SiFN0H1KBE2hvSQ2xvydRv1m2wn8pkea8x7qE/ZEdCK+fMGx2oBDzHt7dNg==", "category"=>{"name"=>"あああ"}, "project_id"=>"newfeature300"} Current user: admin (id=1) WARNING: Can't mass-assign protected attributes for TermCategory: name Rendered plugins/redmine_glossary/app/views/term_categories/_form.html.erb (0.6ms) Rendered plugins/redmine_glossary/app/views/glossary/add_term_category.html.erb within layouts/base (1.7ms) Completed 200 OK in 37ms (Views: 20.2ms | ActiveRecord: 4.5ms)
ぐぐって参考になりそうな情報を集めてみました。
http://qiita.com/aquamikan/items/57c6c95b39f961a18453
Rails 3.xでは、モデルにattr_accessibleを設定しないとフィールド(カラム)を変更できないようです。
Rails 4.xではattr_accessibleが廃止されたとあります。
Redmine Issue Templatesプラグインのモデルを見ると、attr_accessibleが設定されています。
とりあえず動作しているIssue Templatesプラグインをまねて、attr_accessibleをterm_category.rbに追加してみました。
acts_as_list :scope => :project_id
+ attr_accessible :name, :project, :position
+
validates_presence_of :name
Redmineを再起動したところ、新しいカテゴリの追加に成功しました。
高橋 徹 さんが約10年前に更新
用語の追加で[作成]をクリックすると「名称を入力してください」エラーが発生¶
Started POST "/projects/newfeature300/glossary/new" for 127.0.0.1 at 2015-03-21 23:34:25 +0900 Processing by GlossaryController#new as HTML Parameters: {"utf8"=>"?", "authenticity_token"=>"7FdkT17JjYMZhiU0KQMYxeOlai2zMMg6sJO3RfP5DvKwa6gUYV4o9/CN+CQxI+zgJbaru04nqyLZYSalhUiayQ==", "term"=>{"name"=>"ソフトウェア要求仕様", "name_en"=>"Software Requirement Specification", "rubi"=>"", "abbr_whole"=>"", "datatype"=>"", "codename"=>"", "category_id"=>"1", "description"=>"システム要求 から導き出され、ソフトウェアに割り当てられた詳細な要求を文書化したもの"}, "commit"=>"作成", "project_id"=>"newfeature300"} Current user: admin (id=1) WARNING: Can't mass-assign protected attributes for Term: name, name_en, rubi, abbr_whole, datatype, codename, category_id, description Rendered attachments/_form.html.erb (5.6ms) Rendered plugins/redmine_glossary/app/views/glossary/_form.html.erb (15.5ms) Rendered plugins/redmine_glossary/app/views/glossary/new.html.erb within layouts/base (19.9ms) Completed 200 OK in 96ms (Views: 38.9ms | ActiveRecord: 5.3ms)
これも前と同じパターンと思われます。
app/models/term.rb の修正
+ attr_accessible :project, :category, :author, :name, :name_en, :datatype, :codename, :description,
+ :rubi, :abbr_whole
app/models/glossary_styles.rb の修正
belongs_to :project
+ attr_accessible :groupby
def grouping?
高橋 徹 さんが約10年前に更新
既存の用語を編集で変更しても、反映されない¶
ログにエラーはなし。
ログを見ると、HTTPのPATCHメソッドでリクエストが出ている。
Started PATCH "/projects/newfeature300/glossary/1/edit" for 127.0.0.1 at 2015-03-22 00:05:02 +0900 Processing by GlossaryController#edit as HTML Parameters: {"utf8"=>"?", "authenticity_token"=>"w4seWLVAR4NMTyDzinWXquw22/gsr0hJ6azxbe052gyft9IDitfi96VE/eOSVWOPKiUabtG4K1GAXmCNm4hONw==", "term"=>{"name"=>"ソフトウェア要求仕様", "name_en"=>"Software Requirement Specification", "rubi"=>"", "abbr_whole"=>"", "datatype"=>"", "codename"=>"", "category_id"=>"1", "description"=>"システム要求 から導き出され、ソフトウェアに割り当てられた詳細な要求を文書化したもの"}, "commit"=>"編集", "project_id"=>"newfeature300", "id"=>"1"} Current user: admin (id=1) Rendered attachments/_form.html.erb (2.4ms) Rendered plugins/redmine_glossary/app/views/glossary/_form.html.erb (7.3ms) Rendered plugins/redmine_glossary/app/views/glossary/edit.html.erb within layouts/base (10.6ms) Completed 200 OK in 48ms (Views: 32.6ms | ActiveRecord: 4.5ms)
config/routes.rb
にPATCHを追記してみる
- match 'projects/:project_id/glossary/edit', :to => 'glossary#edit', :via => [ :get, :post ]
- match 'projects/:project_id/glossary/:id/edit', :to => 'glossary#edit', :id => /\d+/, :via => [ :get, :post ]
+ match 'projects/:project_id/glossary/edit', :to => 'glossary#edit', :via => [ :get, :post, :patch ]
+ match 'projects/:project_id/glossary/:id/edit', :to => 'glossary#edit', :id => /\d+/, :via => [ :get, :post, :patch ]
app/controller/glossary_controller.rb
のeditメソッドに条件追加
- if request.post? || request.put?
+ if request.post? || request.put? || request.patch?
これで編集はできるようになりました。
高橋 徹 さんが約10年前に更新
用語集一覧のサイドバーの[表示]ボタンを押すとPage not foundエラー¶
ログを見ると
Started PATCH "/glossary_styles/edit?glossary_style_id=1&project_id=newfeature300" for 127.0.0.1 at 2015-03-22 00:20:40 +0900 ActionController::RoutingError (No route matches [PATCH] "/glossary_styles/edit"): vendor/bundler/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' :
なので、config/routes.rb を修正
- match 'glossary_styles/:action', :to => 'glossary_styles', :via => [ :get, :post, :put ]
+ match 'glossary_styles/:action', :to => 'glossary_styles', :via => [ :get, :post, :put, :patch ]
Redmineを再起動、エラー解消を確認。
高橋 徹 さんが約10年前に更新
用語集一覧のサイドバーでソート条件を設定して[表示]するとInternal Error発生¶
ログをみると
Started GET "/projects/newfeature300/glossary" for 127.0.0.1 at 2015-03-22 00:26:41 +0900 Processing by GlossaryController#index as HTML Parameters: {"project_id"=>"newfeature300"} Current user: admin (id=1) Completed 500 Internal Server Error in 16ms NoMethodError (undefined method `sort!' for #<Term::ActiveRecord_Relation:0x00000004ef70a0>): vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:136:in `method_missin g' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:99:in `method_missing ' plugins/redmine_glossary/app/controllers/glossary_controller.rb:230:in `sort_terms' plugins/redmine_glossary/app/controllers/glossary_controller.rb:30:in `index' :
コードは、
def sort_terms(terms, prms) terms.sort! {|a, b|
このメソッドのtermsは、モデルTerm.all の戻り値。Rails 3では配列だったが、Rails 4対応の修正でリレーションに変更したため、sort!メソッドが適用できなくなったのが原因。
- terms.sort! {|a, b|
+ terms.to_a.sort! {|a, b|
Redmineを再起動し、修正結果OK。
高橋 徹 さんが約10年前に更新
用語の一括移動で移動先のプロジェクトを指定し[移動]ボタンを押すとinternal errorが発生¶
ログは
Started POST "/projects/newfeature300/glossary/move_all" for 127.0.0.1 at 2015-03-22 00:42:22 +0900 Processing by GlossaryController#move_all as HTML Parameters: {"utf8"=>"?", "authenticity_token"=>"WWnpdrfct0JQuEbvJwPqZ5FI14BN2oE/MFhWtwqJ0KkFVSUtiEsSNrmzm/8/Ix5CV1sWFrDN4idZqsdXfDhEkg==", "new_project_id"=>"2", "commit"=>"移動", "project_id"=>"newfeature300"} Current user: admin (id=1) Completed 500 Internal Server Error in 43ms ArgumentError (wrong number of arguments (2 for 1)): vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:327:in `update_all' vendor/bundler/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:8:in `update_all' plugins/redmine_glossary/app/controllers/glossary_controller.rb:157:in `move_all'
app/controllers/glossary_controller.rb
を見ると
Term::update_all("project_id = #{newproj.id}", "project_id = #{@project.id}")
Rails 4で2つの引数のupdate_allメソッドは消えたようです。
次のように修正します。
- Term::update_all("project_id = #{newproj.id}", "project_id = #{@project.id}")
+ Term.where(project_id: @project.id).update_all(project_id: newproj.id)
Redmineを再起動し、一括移動をしてみたところOKでした。
高橋 徹 さんが約10年前に更新
ここまでの成果をGithubに上げる¶
作業のベースとなったリポジトリ
https://github.com/maxrossello/redmine_glossary.git
のForkをgithub上に作成し、そこに修正を反映して、できればプルリクエストをしてみる。
まず、クローンした作業ディレクトリ上で(つまりmasterブランチで)変更作業をしていたので、ローカルにブランチを作ってそこへコミットする。
redmine_glossary$ git branch * master redmine_glossary$ git branch feature/redmine-3 redmine_glossary$ git branch feature/redmine-3 * master redmine_glossary$ git checkout feature/redmine-3 M app/controllers/glossary_controller.rb M app/controllers/glossary_styles_controller.rb M app/controllers/term_categories_controller.rb M app/helpers/glossary_port_helper.rb M app/helpers/glossary_styles_helper.rb M app/models/glossary_style.rb M app/models/term.rb M app/models/term_category.rb M app/views/glossary/_sidebar.html.erb M config/routes.rb Switched to branch 'feature/redmine-3' redmine_glossary$
次に、リモートリポジトリをオリジナルからフォークしたものへ差し替えます。
redmine_glossary$ git remote rm origin redmine_glossary$ git remote add origin https://github.com/torutk/redmine_glossary.git
変更をコミットし、リモート(フォーク)へブランチをプッシュします。
redmine_glossary$ git add . redmine_glossary$ git commit -m "updating for Redmine 3.0(Rails 4.2)" [feature/redmine-3 f0fa005] updating for Redmine 3.0(Rails 4.2) 10 files changed, 46 insertions(+), 65 deletions(-) redmine_glossary$ git push -u origin feature/redmine-3 Username for 'https://github.com': torutk Password for 'https://torutk@github.com': Counting objects: 76, done. Compressing objects: 100% (22/22), done. Writing objects: 100% (26/26), 4.13 KiB | 0 bytes/s, done. Total 26 (delta 16), reused 7 (delta 4) To https://github.com/torutk/redmine_glossary.git * [new branch] feature/redmine-3 -> feature/redmine-3 Branch feature/redmine-3 set up to track remote branch feature/redmine-3 from origin. redmine_glossary$
高橋 徹 さんが約10年前に更新
一括移動した用語のリンクが404エラー¶
一括移動した用語のタイトルをリンクすると404エラーとなります。URLを見ると、移動前のプロジェクト識別子が含まれています。
Redmineをコンソールでアクセスして調査¶
redmine$ bundle exec rails console production Loading production environment (Rails 4.2.0) irb(main):001:0> @terms = Term.all => #<ActiveRecord::Relation [#<Term id: 1, project_id: 2, category_id: 1, author_id: 1, updater_id: 1, name: "ソフトウェア要求仕様", name_en: "Software Requirement Specification", datatype: "", codename: "", description: "システム要求から導き出され、ソフトウェアに割り当てられた詳細な要求を文書化したもの", created_on: "2015-03-21 14:43:30", updated_on: "2015-03-21 15:17:53", rubi: "そふとうぇあようきゅうしようしょ", abbr_whole: "", tech_en: "", name_cn: "", name_fr: "">, #<Term id: 2, project_id: 2, category_id: nil, author_id: 1, updater_id: 1, name: "あああ", name_en: "alfa", datatype: "あああ", codename: "あああ", description: "あああああ", created_on: "2015-03-21 14:55:02", updated_on: "2015-03-21 14:55:02", rubi: "あああ", abbr_whole: "あああ", tech_en: "", name_cn: "", name_fr: "">, #<Term id: 3, project_id: 2, category_id: 1, author_id: 1, updater_id: 1, name: "いいい", name_en: "iii", datatype: "i", codename: "iii", description: "いいいい い", created_on: "2015-03-21 15:02:30", updated_on: "2015-03-21 15:02:30", rubi: "いいい", abbr_whole: "い", tech_en: "", name_cn: "", name_fr: "">]> irb(main):006:0> @terms.first.project => #<Project id: 1, name: "新機能確認3.0.0", description: "Redmine 3.0.0の新機能を確認する", homepage: "", is_public: true, parent_id: nil, created_on: "2015-02-21 14:14:04", updated_on: "2015-02-21 14:14:04", identifier: "newfeature300", status: 1, lft: 3, rgt: 4, inherit_members: false> irb(main):007:0> @term1.project_id => 2
と、モデルのprojectを参照するとなぜか以前のものとなっていました。project_idを参照するとデータベースどおりなのですが・・・。
app/models/term.rb
を見てproject関係の箇所を調べてみます。
class Term < ActiveRecord::Base
belongs_to :project
def project
Project.find_by(project_id)
end
RedmineにコンソールアクセスしてProject.find_byの実験
irb(main):028:0> Project.find_by(1) => #<Project id: 1, name: "新機能確認3.0.0", (後略) irb(main):029:0> Project.find_by(2) => #<Project id: 1, name: "新機能確認3.0.0", (後略)
あれあれ、だめですねぇ。
ここで、RailsのActiveRecordの仕様を調べたところ、find_byは引数に条件を指定するとあります。
1や2は条件にはなっていません。id: 1
と指定するか、find_by_idを使うのが正しいと思います。
- Project.find_by(project_id) + Project.find_by_id(project_id)
Redmineを再起動し確認OKです。
高橋 徹 さんが約10年前に更新
Redmineの[管理]メニュー > [設定]をクリックすると、Internal Error発生
production.logには次のエラーが記録されていました。
ActionView::Template::Error (can not load translations from /var/lib/redmine-2.6.1/plugins/redmine_glossary/config/locales/de.yml: #<Psych::SyntaxError: (/var/lib/redmine-2.6.1/plugins/redmine_glossary/config/locales/de.yml): invalid leading UTF-8 octet at line 1 column 1>): 3: <div class="box tabular settings"> 4: <p><%= setting_select :ui_theme, Redmine::Themes.themes.collect {|t| [t.name, t.id]}, :blank => :label_default, :label => :label_theme %></p> :(後略)
/var/lib/redmine/plugins/redmine_glossary/config/locales/de.yml のエンコーディングを調べると
~$ file /var/lib/redmine/plugins/redmine_glossary/config/locales/de.yml de.yml: ISO-8859 text
その他の言語ファイル(yml)はUTF-8なので、これが原因かと。
vimでファイルを開き、:set fenc=utf-8
で保存後、Unicorn再起動
高橋 徹 さんが9年以上前に更新
- ステータス を 進行中 から 終了 に変更
- 進捗率 を 50 から 100 に変更
GitHubに成果をアップしているので終了とします。
https://github.com/torutk/redmine_glossary