プロジェクト

全般

プロフィール

QA #1075

奈良 裕記 さんが3年以上前に更新

h3. ■現象/要望 

 多くのWebサイトでは、指定したページが存在しなかった場合、単に404を表示するのではなく、 
 検索画面などを表示して、ユーザの操作をナビゲートしている。 

 例えば、Githubの場合、404の表示だけでなく、Search boxを表示している。 
 例 
 https://github.com/redmine/redmice 

 しかし、Redmineの場合、入力したissue-noまたはproject-identifierが存在しない場合、単に404を表示するだけである。 

 例 
 https://redmine.org/issues/99999 

 単に404の定型文で無く、各サイトで定義したメッセージとリンクを表示可能にすれば、サーバ管理者の意図を伝え易くなり、Redmineをより使い易くできる。 

 本家チケット起票済 
 https://redmine.org/issues/32844 
 賛成の方は、上記チケットに +1 お願いします。 

 h3. ■解決策 

 h3. ■対応状況 

 画面表示処理自体を変更するには、下記コードを修正すればよい。 
 app/controller/application_controller.rb 
 app/views/common/error.html.erb 

 しかし、エンドユーザ側でカスタマイズ可能にすべきなので、 
 システムで編集可能なWiki画面などにredirectした方が良いと思われる。 

 viewcustomizeで下記エラー画面を加工しても良さそう。 

 banner pluginで関連情報を常時表示する方法もある。 
 正常にアクセスできる場合も表示するのでワークアラウンドとして扱うべきだが。 
 https://github.com/akiko-pusu/redmine_banner/ 

 h3. ■補足 

 関連コード 
 app/controller/application_controller.rb 
 <pre><code class="ruby"> 

   def render_404(options={}) 
     render_error({:message => :notice_file_not_found, :status => 404}.merge(options)) 
     return false 
   end 

  # Renders an error response 
   def render_error(arg) 
     arg = {:message => arg} unless arg.is_a?(Hash) 

     @message = arg[:message] 
     @message = l(@message) if @message.is_a?(Symbol) 
     @status = arg[:status] || 500 

     respond_to do |format| 
       format.html { 
         render :template => 'common/error', :layout => use_layout, :status => @status 
       } 
       format.any { head @status } 
     end 
   end 

 </code></pre> 

 app/views/common/error.html.erb 
 <pre><code class="ruby"> 
 <h2><%= @status %></h2> 

 <% if @message.present? %> 
   <p id="errorExplanation"><%= @message %></p> 
 <% end %> 

 <% if @archived_project && User.current.admin? %> 
   <p><%= link_to l(:button_unarchive), unarchive_project_path(@archived_project), :method => :post, :class => 'icon icon-unlock' %></p> 
 <% end %> 

 <p><a href="javascript:history.back()"><%= l(:button_back) %></a></p> 

 <% html_title @status %> 
 ~ 
 </code></pre> 


 !https://unofficial-redmine.org/matomo/matomo.php?idsite=1&rec=1075! 

戻る