Don't assume resource param is :id when using shallow routes
Since #5581 added support for resources with custom params we should not assume that it is :id when using shallow resource routing.
This commit is contained in:
parent
27619e34d4
commit
cabb4471af
@ -965,6 +965,8 @@ def member_scope
|
||||
"#{path}/:#{param}"
|
||||
end
|
||||
|
||||
alias :shallow_scope :member_scope
|
||||
|
||||
def new_scope(new_path)
|
||||
"#{path}/#{new_path}"
|
||||
end
|
||||
@ -1509,7 +1511,7 @@ def shallow_scoping? #:nodoc:
|
||||
|
||||
def path_for_action(action, path) #:nodoc:
|
||||
prefix = shallow_scoping? ?
|
||||
"#{@scope[:shallow_path]}/#{parent_resource.path}/:id" : @scope[:path]
|
||||
"#{@scope[:shallow_path]}/#{parent_resource.shallow_scope}" : @scope[:path]
|
||||
|
||||
if canonical_action?(action, path.blank?)
|
||||
prefix.to_s
|
||||
|
@ -487,6 +487,12 @@ def self.call(params, request)
|
||||
resources :messages
|
||||
end
|
||||
|
||||
resources :orders do
|
||||
constraints :download => /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do
|
||||
resources :downloads, :param => :download, :shallow => true
|
||||
end
|
||||
end
|
||||
|
||||
scope :as => "routes" do
|
||||
get "/c/:id", :as => :collision, :to => "collision#show"
|
||||
get "/collision", :to => "collision#show"
|
||||
@ -2254,6 +2260,12 @@ def test_custom_param_constraint
|
||||
assert_equal 404, @response.status
|
||||
end
|
||||
|
||||
def test_shallow_custom_param
|
||||
get '/downloads/0c0c0b68-d24b-11e1-a861-001ff3fffe6f.zip'
|
||||
assert_equal 'downloads#show', @response.body
|
||||
assert_equal '0c0c0b68-d24b-11e1-a861-001ff3fffe6f', @request.params[:download]
|
||||
end
|
||||
|
||||
private
|
||||
def with_https
|
||||
old_https = https?
|
||||
|
Loading…
Reference in New Issue
Block a user