Users have subscriptions to feeds but when I change (as suggested elsewhere on stackO)
resource :subscriptions
to
resources: subscriptions
it breaks some ajax functionality I already have implemented regarding destroy.
I want to be able to link to /subscriptions/ and have users be able to view all of their subscriptions. The problem is that currently it’s bringing me to subscriptions#show when I really want #index.
How should I do this?
Here’s my 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>
Here’s my destroy method
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
Using the default resourceful routes for a plural resource, the proper destroy route would be
subscription_path(id), method: :delete. Note that subscription is singular. For these routes, the destroy path is generally identical to the show and update path, with the exception of http method used.