我不知道,因为除了我的应用程序之前正在运行的错误,错误发生在路由中。
ActionController::RoutingError (No route matches {:action=>"show", :controller=>"products", :id=>#<Product id: 10, title: "", code: "", description: "", price: nil, created_at: "2013-06-01 18:52:16", updated_at: "2013-06-01 18:52:16", permalink: nil, image_1_file_name: nil, image_1_content_type: nil, image_1_file_size: nil, image_1_updated_at: nil, image_2_file_name: nil, image_2_content_type: nil, image_2_file_size: nil, image_2_updated_at: nil, image_3_file_name: nil, image_3_content_type: nil, image_3_file_size: nil, image_3_updated_at: nil, image_4_file_name: nil, image_4_content_type: nil, image_4_file_size: nil, image_4_updated_at: nil, image_5_file_name: nil, image_5_content_type: nil, image_5_file_size: nil, image_5_updated_at: nil, image_6_file_name: nil, image_6_content_type: nil, image_6_file_size: nil, image_6_updated_at: nil, image_7_file_name: nil, image_7_content_type: nil, image_7_file_size: nil, image_7_updated_at: nil, image_8_file_name: nil, image_8_content_type: nil, image_8_file_size: nil, image_8_updated_at: nil, weight: nil, width: nil, height: nil, length: nil>}):
app/views/admin/products/index.html.erb:23:in `_app_views_admin_products_index_html_erb__949052465_2267215500'
app/views/admin/products/index.html.erb:12:in `each'
app/views/admin/products/index.html.erb:12:in `_app_views_admin_products_index_html_erb__949052465_2267215500'
是interessant,因为在我看来没有锚来显示,视图是这样的:
<h4>Produtos</h4>
<%= link_to 'Criar produto',new_admin_product_path %>
<table class="table table-striped">
<tr>
<td></td>
<td>Nome do Produto</td>
<td>Categorias</td>
<td>Preço</td>
<td></td>
<td></td>
</tr>
<% @products.each do |p| %>
<tr>
<td><%= image_tag p.image_1.url(:thumb),:height => 30 %></td>
<td><%= p.title %></td>
<td>
<% p.categories.each do |a| %>
<%= a.name %>
<% end %>
</td>
<td><%= to_currency p.price %></td>
<td><%= link_to "Editar",edit_admin_product_path(p.id) %>
<%= link_to "Excluir",p,:method => :delete %></td>
</tr>
<% end %>
<table>
在我的路线中是这样的:
namespace :admin do
get '', :to => 'dashboard#index', :as => '/'
resources :products do
member do
delete :del_p_cat
end
end
resources :categories,:except => [:show]
resources :users
end
我尝试把:except =&gt; [:show]但同样的错误,没有意义,如果没有什么都没有调用动作节目。
在执行rake routes
:
admin_product GET /admin/products/:id(.:format) admin/products#show
和whitout命名空间管理员:
product GET /products/:id(.:format) products#show
这个错误是如此主要,我没有进行,因为一个litle时间工作,当我安装我的嵌套表单不工作更多,我不知道,因为我没有改变的路线。
答案 0 :(得分:0)
似乎错误就在这一行:
link_to "Excluir", p, :method => :delete
应该是
link_to "Excluir", [:admin, p],:method => :delete
答案 1 :(得分:0)
我强烈认为您没有正确使用namespace
请在此处阅读有关Rails Routing for namespace的文档。通过将资源封装在带有模块前缀Admin::
的命名空间中,您也必须在模型中使用该命名空间。
赞:class Admin::ProductsController < ActiveRecord::Base
为此,请使用:
scope '/admin' do
#similar definition
end