Skip to content

Instantly share code, notes, and snippets.

Created March 26, 2017 16:03
Show Gist options
  • Save anonymous/cafc7418a44aa9ee33e84311af10e7c9 to your computer and use it in GitHub Desktop.
Save anonymous/cafc7418a44aa9ee33e84311af10e7c9 to your computer and use it in GitHub Desktop.
%li
= link_to "Remove from collection", remove_from_collection_posts_path(cid: params[:id], pid: post.id), data: { confirm: "Are you sure you want to remove this post?" }, remote: true
def remove_from_collection
if params[:pid].present?
@collection = Collection.find(params[:cid])
@post = Post.find(params[:pid])
if @collection.posts.include? @post
@collection.posts.delete(@post)
@collection.save
@collection.touch
render :js => "post_removed();"
end
end
end
function post_removed() {
alert("DONE");
}
function not_removed() {
alert("NOT DONE");
}
$.ajax({
type: "GET",
url: "/posts/remove_from_collection",
data: { pid: <%= params[:pid] %>, cid: <%= params[:cid] %> },
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment