views:

29

answers:

2

I have following in my routes.rb:

namespace "admin" do
  resources :categories
end

resources :categories

and all works well. However, as I remove or comment out: "resources :categories" part

namespace "admin" do
  resources :categories
end

#resources :categories

I am getting:

ActionView::Template::Error (undefined method `category_path' for #<#:0x103fcd4c0>):

once accessing /admin/categories

?? thanks

and here is the index view:

<% @admin_categories.each do |admin_category| %>
  <tr>
    <td><%= link_to 'Show', admin_category %></td>
    <td><%= link_to 'Edit', edit_admin_category_path(admin_category) %></td>
    <td><%= link_to 'Destroy', admin_category, :confirm => 'Are you sure?', :method =>     :delete %></td>
  </tr>
 <% end %>
</table>

<br />

 <%= link_to 'New Category', new_admin_category_path %>

and views and controller were generated by:

rails g scaffold_controller Admin/Category

so it is either a bug or I am doing something completely wrong

+2  A: 

Try: admin_category_path(@category) or [:admin, @category]

You can check what routes are available with:

rake routes

The second shortcut form may be used this way:

form_for [:admin, @category]

link_to 'Show', [:admin, @category]
gertas
+1  A: 

Hi, It's probable that you have a

link_to 'category', category_path(category)

or

link_to 'category', category

in your admin/categories view, or in a partial rendered on this view. As gertas suggests, replace these links with link_to 'category', [:admin, @category] or with link_to 'category', admin_category_path(category).

Yannis
hmm but I did use "rails g scaffold_controller Admin/Category"
bogumbiker
and my index view has following:
bogumbiker
updated my question
bogumbiker
If you have `resources :categories` outside of a name sapce, your `link_to 'Show', admin_category` is equivalent to `link_to 'Show', category_path(admin_category)`. Change it to `link_to 'Show', [:admin, admin_category]`to get the equivalent to link_to 'Show', admin_category_path(admin_category`.
Yannis
ok it helped by doing category_path(admin_category). Just wondering why scaffold generator did wrong spelling?
bogumbiker