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

しかし、コントローラーのdestroyメソッドに入ることができないようです:(

ただし、削除すると

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

form_for の method パラメータを指定すると、コントローラ no pb の create メソッドにたどり着きます。

理解できません....

アレックス

ps: これは、リレーションシップのレーキ ルートの結果です。

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 に答える