Created
March 26, 2017 16:03
-
-
Save anonymous/cafc7418a44aa9ee33e84311af10e7c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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