开发者

Correctly mapping rails url

开发者 https://www.devze.com 2023-03-01 03:18 出处:网络
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 navi

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

end

What 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!

0

精彩评论

暂无评论...
验证码 换一张
取 消