Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

raise original exception instead of routing error when a static page …

…exists but attempts to render a nonexistent partial
  • Loading branch information...
commit 7132e091c347585aeb306aee7aa2401fd67bf1f0 1 parent 50918c3
@jdewyea jdewyea authored
View
12 app/controllers/high_voltage/pages_controller.rb
@@ -2,7 +2,13 @@ class HighVoltage::PagesController < ApplicationController
unloadable
- rescue_from ActionView::MissingTemplate, :with => :invalid_page
+ rescue_from ActionView::MissingTemplate do |exception|
+ if exception.message =~ %r{Missing template pages/}
+ raise ActionController::RoutingError, "No such page: #{params[:id]}"
+ else
+ raise exception
+ end
+ end
def show
render :template => current_page
@@ -10,10 +16,6 @@ def show
protected
- def invalid_page
- raise ActionController::RoutingError, "No such page: #{params[:id]}"
- end
-
def current_page
"pages/#{params[:id].to_s.downcase}"
end
View
2  test/dummy/app/views/pages/exists_but_references_nonexistent_partial.html.erb
@@ -0,0 +1,2 @@
+hello <%= 'world' %>
+<%= render 'nonexistent' %>
View
5 test/pages_controller_test.rb
@@ -17,4 +17,9 @@ class HighVoltage::PagesControllerTest < ActionController::TestCase
end
end
+ should "raise missing template error for valid page with invalid partial" do
+ assert_raise ActionView::MissingTemplate do
+ get :show, :id => "exists_but_references_nonexistent_partial"
+ end
+ end
end

0 comments on commit 7132e09

Please sign in to comment.
Something went wrong with that request. Please try again.