Skip to content

Commit

Permalink
return 404 on broken asset links
Browse files Browse the repository at this point in the history
  • Loading branch information
jlapier committed Feb 23, 2012
1 parent c15ac87 commit afd0788
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 13 additions & 8 deletions app/controllers/application_controller.rb
Expand Up @@ -27,16 +27,21 @@ class ApplicationController < ActionController::Base

private
def broken_link
flash[:warning] = "The page you were looking for was not found."
error_page_id = SiteSetting.read_setting 'error page id'
if error_page_id
page = ContentPage.find error_page_id
if page and page.ready_for_publishing?
redirect_to page
return
if request.url =~ /content_page_assets/
render :status => 404
else
logger.info "Broken link: #{request.url}"
flash[:warning] = "The page you were looking for was not found. (#{request.url})"
error_page_id = SiteSetting.read_setting 'error page id'
if error_page_id
page = ContentPage.find error_page_id
if page and page.ready_for_publishing?
redirect_to page
return
end
end
redirect_to "/"
end
redirect_to "/"
end

# returns true if resource & action in question are designated as public
Expand Down
10 changes: 8 additions & 2 deletions app/views/errors/routing.html.erb
@@ -1,2 +1,8 @@
<h1>Errors#routing</h1>
<p>Find me in app/views/errors/routing.html.erb</p>
<h1>Error: File not Found</h1>
<p>
The asset was not found on the server.
</p>

<p><em>What does this mean?</em></p>

<p>Most likely, someone uploaded an image or a document and created a link to it from within a page, but then later the image or document was deleted, so the link is now broken.</p>

0 comments on commit afd0788

Please sign in to comment.