繁体   English   中英

Rails 3:无法使form_for在RESTful achitecture之后作为“删除”工作=>总是给出一个ROUTING ERROR

[英]Rails 3 : Can't get form_for to work as a 'delete' following the RESTful achitecture => always giving a ROUTING ERROR

我有一个非常简单的渲染,如下所示:

<%= form_for(:relationships, :url => relationships_path, :html => {:method => 'delete'}) do |f| %>
<div><%= f.hidden_field :user_id_to_unfollow, :value => @user.id %></div>
<div class="actions"><%= f.submit "Unfollow" %></div>
<% end %>

当我提交此表格时,它总会给我一个

Routing Error
No route matches "/relationships"

在我的页面上。

在我的关系控制器中,我创建了所有的propers方法:

def create    
...
end

def destroy    
...
end

def update    
...
end

def show    
...
end

在我的路由配置中,我确保允许关系控制器的所有路由

resources :relationships

但我似乎无法进入控制器的destroy方法:(

但是如果我删除了

:html => {:method => 'delete'}

form_for中的方法参数然后我得到控制器的创建方法没有pb。

我不明白......

亚历克斯

ps:这是关系的rake路由结果:

relationships GET    /relationships(.:format)          {:action=>"index", :controller=>"relationships"}
              POST   /relationships(.:format)          {:action=>"create", :controller=>"relationships"}

您应该将delete请求指向单个资源URL,例如。 relationships/4325 运行rake routes以查看哪些url / verb组合有效。

- 编辑

关系资源的路线:

resources :relationships, :only => [:index, :create, :destroy]

取消关注按钮(为自己创建一个表单):

= button_to "Unfollow", relationship_path(relationship), :method => 'delete'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM