Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from anonymous/_post.html.haml
Last active March 26, 2017 16:17
Show Gist options
  • Save tbuehlmann/0c83748d920c802e06f2b9e4f12498f6 to your computer and use it in GitHub Desktop.
Save tbuehlmann/0c83748d920c802e06f2b9e4f12498f6 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
respond_to do |format|
format.js { render :js => "post_removed();" }
end
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