Correctly mapping rails url
I have a controller in a subdirectory called fridges (the higher-level directory it is in is called categories). I have made an index page for the fridges controller and it works correctly when I navigate to "categories/fridges/index". However, it doesn't work when browsing to 'categories/fridges' as I want it to.
Here is how it 开发者_开发问答is being routed in the route config:
map.namespace :categories do |categories|
categories.resources :fridges endWhat should I be doing to make the index page appear when navigating to the url 'categories/fridges' ?
In Rails 3, you can do:
namespace 'category' do
match '/fridges' => 'fridges#index'
resources :fridges
end
A similar approach can be taken for Rails 2.x. What you are looking for is the match '/fridges' => 'fridges#index', which should be defined in your namespace.
Hope that helps!
精彩评论