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
|
def show
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
|
@custom_values = @user.custom_values.find(:all, :include => :custom_field)
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
# Login request and validation
|
# Login request and validation
|
||||||
|
|
|
@ -103,6 +103,12 @@ class ApplicationController < ActionController::Base
|
||||||
redirect_to_url session[:return_to]
|
redirect_to_url session[:return_to]
|
||||||
session[:return_to] = nil
|
session[:return_to] = nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_404
|
||||||
|
@html_title = "404"
|
||||||
|
render :template => "common/404", :layout => true, :status => 404
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
# qvalues http header parser
|
# qvalues http header parser
|
||||||
|
|
|
@ -41,8 +41,7 @@ class DocumentsController < ApplicationController
|
||||||
@attachment.increment_download
|
@attachment.increment_download
|
||||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||||
rescue
|
rescue
|
||||||
flash.now[:notice] = l(:notice_file_not_found)
|
render_404
|
||||||
render :text => "", :layout => true, :status => 404
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_attachment
|
def add_attachment
|
||||||
|
@ -62,5 +61,7 @@ private
|
||||||
def find_project
|
def find_project
|
||||||
@document = Document.find(params[:id])
|
@document = Document.find(params[:id])
|
||||||
@project = @document.project
|
@project = @document.project
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,8 +35,10 @@ class IssueCategoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@category = IssueCategory.find(params[:id])
|
@category = IssueCategory.find(params[:id])
|
||||||
@project = @category.project
|
@project = @category.project
|
||||||
end
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -132,8 +132,7 @@ class IssuesController < ApplicationController
|
||||||
@attachment = @issue.attachments.find(params[:attachment_id])
|
@attachment = @issue.attachments.find(params[:attachment_id])
|
||||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||||
rescue
|
rescue
|
||||||
flash.now[:notice] = l(:notice_file_not_found)
|
render_404
|
||||||
render :text => "", :layout => true, :status => 404
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -141,5 +140,7 @@ private
|
||||||
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
||||||
@project = @issue.project
|
@project = @issue.project
|
||||||
@html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
|
@html_title = "#{@project.name} - #{@issue.tracker.name} ##{@issue.id}"
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,9 +33,11 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@member = Member.find(params[:id])
|
@member = Member.find(params[:id])
|
||||||
@project = @member.project
|
@project = @member.project
|
||||||
end
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,8 +51,10 @@ class NewsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def find_project
|
def find_project
|
||||||
@news = News.find(params[:id])
|
@news = News.find(params[:id])
|
||||||
@project = @news.project
|
@project = @news.project
|
||||||
end
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -500,8 +500,8 @@ private
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
@html_title = @project.name
|
@html_title = @project.name
|
||||||
rescue
|
rescue ActiveRecord::RecordNotFound
|
||||||
redirect_to :action => 'list'
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
# Retrieve query from session or build a new query
|
# Retrieve query from session or build a new query
|
||||||
|
|
|
@ -45,5 +45,7 @@ private
|
||||||
@project = @query.project
|
@project = @query.project
|
||||||
# check if user is allowed to manage queries (same permission as add_query)
|
# check if user is allowed to manage queries (same permission as add_query)
|
||||||
authorize('projects', 'add_query')
|
authorize('projects', 'add_query')
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -98,10 +98,12 @@ class ReportsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Find project of id params[:id]
|
# Find project of id params[:id]
|
||||||
def find_project
|
def find_project
|
||||||
@project = Project.find(params[:id])
|
@project = Project.find(params[:id])
|
||||||
end
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
def issues_by_tracker
|
def issues_by_tracker
|
||||||
@issues_by_tracker ||=
|
@issues_by_tracker ||=
|
||||||
|
|
|
@ -63,6 +63,8 @@ private
|
||||||
@path = params[:path].squeeze('/').gsub(/^\//, '') if params[:path]
|
@path = params[:path].squeeze('/').gsub(/^\//, '') if params[:path]
|
||||||
@path ||= ''
|
@path ||= ''
|
||||||
@rev = params[:rev].to_i if params[:rev] and params[:rev].to_i > 0
|
@rev = params[:rev].to_i if params[:rev] and params[:rev].to_i > 0
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_error
|
def show_error
|
||||||
|
|
|
@ -39,8 +39,7 @@ class VersionsController < ApplicationController
|
||||||
@attachment.increment_download
|
@attachment.increment_download
|
||||||
send_file @attachment.diskfile, :filename => @attachment.filename
|
send_file @attachment.diskfile, :filename => @attachment.filename
|
||||||
rescue
|
rescue
|
||||||
flash.now[:notice] = l(:notice_file_not_found)
|
render_404
|
||||||
render :text => "", :layout => true, :status => 404
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_file
|
def destroy_file
|
||||||
|
@ -53,5 +52,7 @@ private
|
||||||
def find_project
|
def find_project
|
||||||
@version = Version.find(params[:id])
|
@version = Version.find(params[:id])
|
||||||
@project = @version.project
|
@project = @version.project
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
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