首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Rails 3销毁链路不工作

Rails 3销毁链路不工作
EN

Stack Overflow用户
提问于 2011-05-26 15:12:50
回答 4查看 3.5K关注 0票数 1

我的销毁链接不起作用。

我的索引视图:

代码语言:javascript
运行
复制
<div id="konkurrancer"><%= render 'konkurrencer', :remote => true %></div><%= debug(params) %>

我的konkurrencer部分:

代码语言:javascript
运行
复制
<% for konkurrancer in @konkurrancers %>    <%= link_to 'Destroy', [:admin, konkurrancer], :method => :delete %> <% end %>

我得到了这个错误:

代码语言:javascript
运行
复制
No route matches {:action=>"show", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, Føtex eller Netto

视图中的编辑错误:

代码语言:javascript
运行
复制
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", :controller=>"admin/konkurrancers", :id=>#<Konkurrancer id: 41, name: " Vind 16.000 kr., til Bilka, 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>

Rake路由:

代码语言:javascript
运行
复制
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"}

我的路由文件:

代码语言:javascript
运行
复制
namespace :admin do
resources :tags
resources :kategoris
 resources :konkurrancers do
      collection do
        delete :delete_multiple
      end
    end
resources :reklamers
   end 
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-05-26 15:16:48

您可能需要将其更改为类似以下内容:

代码语言:javascript
运行
复制
<%= link_to 'Destroy', :action => 'destroy', :id => konkurrancer.id, :method => :delete %>

或者,如果您使用RESTful路由,则如下所示:

代码语言:javascript
运行
复制
<%= link_to 'Destroy', delete_konkurrancer(:id => konkurrancer.id), :method => :delete %>
票数 2
EN

Stack Overflow用户

发布于 2011-05-26 15:15:27

如果您使用的是RESTful资源,请尝试以下操作:

代码语言:javascript
运行
复制
<%= link_to 'Destroy', [:admin, konkurrancer], :method => :delete %>
票数 6
EN

Stack Overflow用户

发布于 2011-06-04 00:07:45

在使用名称空间控制器和路由时,必须使用名称空间模型才能使link_to辅助对象正常工作。

当我为模型编写额外的管理页面时,我还在admin名称空间中生成一些包装器模型。

例如,在app/model/admin/person.rb中

代码语言:javascript
运行
复制
class Admin::Person < Person    
end

使各种形式和链接变得更加简单。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6134988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档