Using custom `map.connect` routes from inside resources in Rails 3
Here are some Rails 2 routes from gitorious.org.[code lang='ruby']
map.resources :repositories do |repo|
map.resources :repositories do |repo|
repo.resources :comments
repo.trees "trees", :controller => "trees", :action => "index"
repo.tree "trees/*branch_and_path", :controller => "trees", :action => "show"
repo.trees "trees", :controller => "trees", :action => "index"
repo.tree "trees/*branch_and_path", :controller => "trees", :action => "show"
end
[/code]My first attempt at writing that in Rails 3 routes looked like this. [code lang='ruby']
resources :repositories do
resources :comments
match "trees" => "trees#index", :as => :tree
match "trees/*branch_and_path" => "trees#show", :as => :tree
end
[/code]That broke the app with the message can't define route directly in resources scope.You need to specify where the base should be: member or collection.[code lang='ruby']
resources :repositories do
resources :comments
collection do
match "trees" => "trees#index", :as => :tree
match "trees/*branch_and_path" => "trees#show", :as => :tree
end
end
[/code]Rails 2 assumed you were working on the collection, Rails 3 doesn't.
resources :repositories do
resources :comments
match "trees" => "trees#index", :as => :tree
match "trees/*branch_and_path" => "trees#show", :as => :tree
end
[/code]That broke the app with the message can't define route directly in resources scope.You need to specify where the base should be: member or collection.[code lang='ruby']
resources :repositories do
resources :comments
collection do
match "trees" => "trees#index", :as => :tree
match "trees/*branch_and_path" => "trees#show", :as => :tree
end
end
[/code]Rails 2 assumed you were working on the collection, Rails 3 doesn't.