Andrew D
Andrew D

Reputation: 116

Ruby on Rails 3.2.1 Routes

Just started converting my second app from rails 2.3.11 to 3.2.1 - I've hit a problem however with my routes..

This is my old routes file:

map.namespace(:admin) do |admin|
 admin.resources :products, :has_many => [:categories, :product_versions, :extra_documents]
 admin.resources :product_versions, :has_many => [:sub_versions]
 admin.resources :categories, :has_many => [:sub_categories, :sub_emanuals, :sub_tests]
end

This is what I now have in my rails3 routes.rb file:

namespace :admin do
  resources :products
  resources :product_versions
  resources :categories
end

This seems to be causing problems in my view where I have this:

<%= link_to "Edit Categories", admin_product_categories_url(product) %>

as in rails 3 is no longer understands what this is, I use this format A LOT in this application. I tried to work around this after seeing the output of "rake routes" and I used:

<%= link_to "Edit Categories", admin_categories_url(product) %>

However, in the html code served up it gave me a URL of "http://localhost:3000/admin/categories.21" - see the .21 not /21

Can anyone else on this one please?

Thanks in advance, Andrew

Upvotes: 0

Views: 1230

Answers (1)

mark
mark

Reputation: 10564

Should be

  admin_category_url(category)

ie. one category

Having said that,

Don't you want:

admin_product_category(product, category)

In which case you need to nest your routes:

namespace :admin do
  resources :products do
    resources :categories
  end
  resources :product_versions
end

Upvotes: 2

Related Questions