ユーザーはフィードのサブスクリプションを持っていますが、私が変更すると(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