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 :c开发者_高级运维ategories
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
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]
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)
.
精彩评论