1

ユーザーはフィードのサブスクリプションを持っていますが、私が変更すると(stackOの他の場所で提案されているように)

resource :subscriptions 

resources: subscriptions 

それは私が破壊に関してすでに実装したいくつかのajax機能を壊します。

/ subsets /にリンクして、ユーザーがすべてのサブスクリプションを表示できるようにしたいと思います。問題は、現在、本当に#indexが必要なときにsubscriptions#showに移動することです。

これはどのようにすればよいですか?

これが私のAJAXです:

<div id="subscribe" class="shadow">
<% if session[:read_random]
    unless is_subscribed?(session[:read_random].last)%>
            <%= link_to 'Subscribe', subscriptions_path(feed_id: session[:read_random].last), method: :post, remote: :true %>

    <% else %>
        <%= link_to 'Unsubscribe', subscriptions_path(feed_id: session[:read_random].last), method: :delete, remote: :true %>

<%  end
   end %>
</div>

これが私の破壊方法です

def destroy

      if params[:feed_id]
          #this is the ajax call
          @subscription = Subscription.find_by_user_id_and_feed_id(session[:user_id], params[:feed_id])
      else
          #this is the index destroy call (unsubscribe)
          @subscription = Subscription.find(params[:id])
      end
  @subscription.destroy

  respond_to do |format|
    format.html { redirect_to request.referer }
    format.js
    format.json { head :no_content }
  end
end
4

1 に答える 1

0

複数のリソースにデフォルトのリソースフルルートを使用すると、適切な破棄ルートはになりますsubscription_path(id), method: :delete。サブスクリプションは特異であることに注意してください。これらのルートの場合、destroyパスは、使用されるhttpメソッドを除いて、showおよびupdateパスと一般的に同じです。

于 2012-06-15T05:34:07.160 に答える