ActiveRecord::RecordNotFound exceptions handled more gracefully
git-svn-id: http://redmine.rubyforge.org/svn/trunk@133 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e7caec6e7d
commit
e3becc7c3c
|
@ -28,6 +28,8 @@ class AccountController < ApplicationController
|
|||
def show
|
||||
@user = User.find(params[:id])
|
||||
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Login request and validation
|
||||
|
|
|
@ -103,6 +103,12 @@ class ApplicationController < ActionController::Base
|
|||
redirect_to_url session[:return_to]
|
||||
session[:return_to] = nil
|
||||
end
|
||||
end
|
||||
|
||||
def render_404
|
||||
@html_title = "404"
|
||||
render :template => "common/404", :layout => true, :status => 404
|
||||
return false
|
||||
end
|
||||
|
||||
# qvalues http header parser
|
||||
|
|
|
@ -41,8 +41,7 @@ class DocumentsController < ApplicationController
|
|||
@attachment.increment_download
|
||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||
rescue
|
||||
flash.now[:notice] = l(:notice_file_not_found)
|
||||
render :text => "", :layout => true, :status => 404
|
||||
render_404
|
||||
end
|
||||
|
||||
def add_attachment
|
||||
|
@ -62,5 +61,7 @@ private
|
|||
def find_project
|
||||
@document = Document.find(params[:id])
|
||||
@project = @document.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,8 +35,10 @@ class IssueCategoriesController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
def find_project
|
||||
@category = IssueCategory.find(params[:id])
|
||||
@project = @category.project
|
||||
end
|
||||
@project = @category.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -132,8 +132,7 @@ class IssuesController < ApplicationController
|
|||
@attachment = @issue.attachments.find(params[:attachment_id])
|
||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||
rescue
|
||||
flash.now[:notice] = l(:notice_file_not_found)
|
||||
render :text => "", :layout => true, :status => 404
|
||||
render_404
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -141,5 +140,7 @@ private
|
|||
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||
@project = @issue.project
|
||||
@html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,9 +33,11 @@ class MembersController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
def find_project
|
||||
@member = Member.find(params[:id])
|
||||
@project = @member.project
|
||||
end
|
||||
@project = @member.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -51,8 +51,10 @@ class NewsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
def find_project
|
||||
@news = News.find(params[:id])
|
||||
@project = @news.project
|
||||
end
|
||||
@project = @news.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -500,8 +500,8 @@ private
|
|||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
@html_title = @project.name
|
||||
rescue
|
||||
redirect_to :action => 'list'
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# Retrieve query from session or build a new query
|
||||
|
|
|
@ -45,5 +45,7 @@ private
|
|||
@project = @query.project
|
||||
# check if user is allowed to manage queries (same permission as add_query)
|
||||
authorize('projects', 'add_query')
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,10 +98,12 @@ class ReportsController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
# Find project of id params[:id]
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
end
|
||||
# Find project of id params[:id]
|
||||
def find_project
|
||||
@project = Project.find(params[:id])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def issues_by_tracker
|
||||
@issues_by_tracker ||=
|
||||
|
|
|
@ -63,6 +63,8 @@ private
|
|||
@path = params[:path].squeeze('/').gsub(/^\//, '') if params[:path]
|
||||
@path ||= ''
|
||||
@rev = params[:rev].to_i if params[:rev] and params[:rev].to_i > 0
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def show_error
|
||||
|
|
|
@ -39,8 +39,7 @@ class VersionsController < ApplicationController
|
|||
@attachment.increment_download
|
||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||
rescue
|
||||
flash.now[:notice] = l(:notice_file_not_found)
|
||||
render :text => "", :layout => true, :status => 404
|
||||
render_404
|
||||
end
|
||||
|
||||
def destroy_file
|
||||
|
@ -53,5 +52,7 @@ private
|
|||
def find_project
|
||||
@version = Version.find(params[:id])
|
||||
@project = @version.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<h2>404</h2>
|
||||
|
||||
<p><%= l(:notice_file_not_found) %></p>
|
||||
<p><a href="javascript:history.back()">Back</a></p>
|
Loading…
Reference in New Issue