-
-
Save tbuehlmann/0c83748d920c802e06f2b9e4f12498f6 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 | |
respond_to do |format| | |
format.js { render :js => "post_removed();" } | |
end | |
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