Emotion Wave Tech Blog

福岡にあるエモーションウェーブ株式会社のエンジニアが書いています。

Redmine1.3.0でLocal avatars Pluginを動くようにした

Redmineを1.3.0にバージョンアップしたのですが、Local avatars Pluginがうまく動かなかったので、少々修正しました。 3つの問題と、僕なりの解決方法を。結構時間掛かったorz

【問題1】個人設定の表示が崩れる

原因は、変な位置にpluginのhtmlが挿入されていたから。 以下のファイルを修正。 1行目を修正、18行目を追加。

vendor/plugins/redmine_local_avatars/app/views/my/_avatar.rhtml

</fieldset>
<h3><%= l(:label_avatar)%></h3>

<div class='box tabular'>
  <div style="width: 128px; height: 128px; border: 1px silver solid;">
    <%= avatar(@user, :size => "128") %>
    <% av = user.attachments.find_by_description('avatar') %>
    <% if not av.nil? %>
      <%= link_to image_tag('delete.png'), attachment_path(av),
                                             :method => :delete,
                                             :confirm => l(:text_are_you_sure),
                                             :class => 'delete',
                                             :title => l(:button_delete) %>
    <% end %>
  </div><br>

  <%= file_field_tag "avatar" %><br />
</div>

【問題2】個人設定で画像の削除を行うとエラー

原因は、添付ファイル削除時に呼ぶメソッドの指定が誤っていたから。 これも以下のファイルを修正。 9、10行目辺り。呼ぶコントローラーの指定、methodの指定を修正。

vendor/plugins/redmine_local_avatars/app/views/my/_avatar.rhtml

</fieldset>
<h3><%= l(:label_avatar)%></h3>

<div class='box tabular'>
  <div style="width: 128px; height: 128px; border: 1px silver solid;">
    <%= avatar(@user, :size => "128") %>
    <% av = user.attachments.find_by_description('avatar') %>
    <% if not av.nil? %>
      <%= link_to image_tag('delete.png'), attachment_path(av),
                                             :method => :delete,
                                             :confirm => l(:text_are_you_sure),
                                             :class => 'delete',
                                             :title => l(:button_delete) %>
    <% end %>
  </div><br>

  <%= file_field_tag "avatar" %><br />
</div>

【問題3】個人設定で画像を設定して保存するとInternalエラー

原因はformタグにmultipartが指定されていないからでした。 プラグイン側でmultipartの指定をしようと試行錯誤したのですが、解決できず。 結局、app/views/my/account.html.erbのformタグに直接「:multipart => true」を追加しました。 以下のページを参考。 Local avatars Plugin v.0.0.1 - Redmine

app/views/my/account.html.erb

<% form_for :user, @user, :url => { :action => &quot;account&quot; },
                          :builder => TabularFormBuilder,
                          :lang => current_language,
                          :html => { :id => 'my_account_form', :multipart => true } do |f| %>

これが一番解決に時間が掛かりました。pluginのhookでやろうとしたけど全然出来ない。。。という状態。 結局、前のバージョンのRedmineにこのpluginを入れた時も同じことやってました。 なので、Redmineのバージョンアップが原因ではないですねorz

とりあえず解決したって感じです。 ruby on rails難しい。。