Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Generate routes for nested resources with nil object raise RoutingErr…

…or [#4262 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit cfb31edb5441f0b12693a3b509dadf87fe1df843 1 parent 1d73682
@spastorino spastorino authored jeremy committed
View
1  actionpack/lib/action_controller/routing/route_set.rb
@@ -174,6 +174,7 @@ def define_url_helper(route, name, kind, options)
#
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(*args) # def users_url(*args)
+ args.compact! #
#
#{generate_optimisation_block(route, kind)} # #{generate_optimisation_block(route, kind)}
#
View
15 actionpack/test/template/url_helper_test.rb
@@ -566,6 +566,10 @@ def show
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
end
+ def show_workshop_of_nil_sessions
+ render :inline => "<%= workshop_sessions_path(nil) %>"
+ end
+
def rescue_action(e) raise e end
end
@@ -612,6 +616,16 @@ def test_existing_nested_resource
end
end
+ def test_existing_nested_resource_with_nil_id
+ @controller = SessionsController.new
+
+ with_restful_routing do
+ assert_raise ActionController::RoutingError do
+ get :show_workshop_of_nil_sessions
+ end
+ end
+ end
+
protected
def with_restful_routing
with_routing do |set|
@@ -619,6 +633,7 @@ def with_restful_routing
map.resources :workshops do |w|
w.resources :sessions
end
+ map.show_workshop_of_nil_sessions 'sessions/show_workshop_of_nil_sessions', :controller => 'sessions', :action => 'show_workshop_of_nil_sessions'
end
yield
end
Please sign in to comment.
Something went wrong with that request. Please try again.