问题描述
|
我的销毁链接不起作用。
我的索引视图:
<div id=\"konkurrancer\"><%= render \'konkurrencer\',:remote => true %></div><%= debug(params) %>
我的konkurrencer部分:
<% for konkurrancer in @konkurrancers %> <%= link_to \'Destroy\',[:admin,konkurrancer],:method => :delete %> <% end %>
我得到这个错误:
No route matches {:action=>\"show\",:controller=>\"admin/konkurrancers\",:id=>#<Konkurrancer id: 41,name: \" Vind 16.000 kr.,til Bilka,Føtex eller Netto
视图中的编辑错误:
ActionController::RoutingError in Admin/konkurrancers#index
Showing C:/Rails/konkurranceportalen/app/views/admin/konkurrancers/_konkurrencer.html.erb where line #59 raised:
No route matches {:action=>\"show\",Føtex eller Netto\",banner1: \"http://partner.smartresponse-media.com/42/1092/1210...\",banner2: \"http://partner.smartresponse-media.com/42/1092/1210...\",vaerdi: 16000,note: \"\",udtraekkes: \"2011-05-31 22:00:00\",created_at: \"2011-05-04 12:35:44\",updated_at: \"2011-05-05 14:55:35\",cached_slug: \"vind-16000-kr-til-bilka-f\\xC3\\xB8tex-eller-netto\",tid: \"4 min\",form: \"Quiz\",rating_score: 5,ratings: 1,rating: 5,photo_file_name: nil,photo_content_type: nil,photo_file_size: nil,photo_updated_at: nil,photo2_file_name: nil,photo2_content_type: nil,photo2_file_size: nil,photo2_updated_at: nil,image_remote_url: \"\",image_remote_url_2: \"\">}
Extracted source (around line #59):
56: <td><%= konkurrancer.form %></td>
57: <td><%= link_to \'Vis\',admin_konkurrancer_path(konkurrancer.id) %></td>
58: <td><%= link_to \'Redigere\',{:action => \'edit\',:id => konkurrancer.id},:class => \'action edit\' %></td>
59: <td> <%= link_to \'Destroy\',admin_konkurrancer_path(konkurrancer),:method => :delete %> </td>
60:
61:
62: </td>
耙道:
delete_multiple_admin_konkurrancers DELETE /admin/konkurrancers/delete_multiple(
.:format) {:action=>\"delete_multiple\",:controller=>\"admin/konkurrancers\"}
admin_konkurrancers GET /admin/konkurrancers(.:format)
{:action=>\"index\",:controller=>\"admin/konkurrancers\"}
POST /admin/konkurrancers(.:format)
{:action=>\"create\",:controller=>\"admin/konkurrancers\"}
new_admin_konkurrancer GET /admin/konkurrancers/new(.:format)
{:action=>\"new\",:controller=>\"admin/konkurrancers\"}
edit_admin_konkurrancer GET /admin/konkurrancers/:id/edit(.:forma
t) {:action=>\"edit\",:controller=>\"admin/konkurrancers\"}
admin_konkurrancer GET /admin/konkurrancers/:id(.:format)
{:action=>\"show\",:controller=>\"admin/konkurrancers\"}
PUT /admin/konkurrancers/:id(.:format)
{:action=>\"update\",:controller=>\"admin/konkurrancers\"}
DELETE /admin/konkurrancers/:id(.:format)
{:action=>\"destroy\",:controller=>\"admin/konkurrancers\"}
我的路线文件:
namespace :admin do
resources :tags
resources :kategoris
resources :konkurrancers do
collection do
delete :delete_multiple
end
end
resources :reklamers
end
解决方法
您可能需要将其更改为以下内容:
<%= link_to \'Destroy\',:action => \'destroy\',:id => konkurrancer.id,:method => :delete %>
或者,如果您使用RESTful路由,则类似于:
<%= link_to \'Destroy\',delete_konkurrancer(:id => konkurrancer.id),:method => :delete %>
,如果您使用的是RESTful资源,请尝试以下操作:
<%= link_to \'Destroy\',[:admin,konkurrancer],:method => :delete %>
,使用命名空间的控制器和路由时,必须使用命名空间的模型才能使link_to
帮助程序正常运行。
当我为模型编写额外的管理页面时,我还会在admin
命名空间中生成一些包装模型。
例如,在app / models / admin / person.rb中
class Admin::Person < Person
end
使各种形式和链接变得更加简单。
,如果是RESTful资源,请尝试以下操作:
{<%= link_to \'Destroy\',:method => :delete %>}
并使用适当的javascript助手。
这是rails的javascript-helper的问题。您需要适当地使用rails.js。如果您使用prototype.js,则在rails.js中,您需要原型帮助器方法;否则,如果您使用jquery,则需要rails jquery帮助器。