1

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

<%= 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"

在我的页面上。

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

def create    
...
end

def destroy    
...
end

def update    
...
end

def show    
...
end

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

resources :relationships

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

但是,如果我删除

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

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

我不明白......

亚历克斯

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

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

1 回答 1

4

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

- 编辑

关系资源的路由:

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

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

= button_to "Unfollow", relationship_path(relationship), :method => 'delete'
于 2011-01-17T10:50:50.953 回答