Skip to content

Instantly share code, notes, and snippets.

@cbmeeks
Created January 29, 2011 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbmeeks/801581 to your computer and use it in GitHub Desktop.
Save cbmeeks/801581 to your computer and use it in GitHub Desktop.
class LikesController < ApplicationController
before_filter :get_ids
respond_to :json
def videolink
results = {}
# check to see if the user has liked this videolink before
if current_user
liked = Like.video?(current_user, @vid_id)
results["status"] = "OK"
results["liked"] = liked
else
results = {}
results["status"] = "Error"
results["message"] = "User not logged in"
end
respond_with( results.to_json )
end
def update
results = {}
if current_user
results["status"] = "OK"
else
results = {}
results["status"] = "Error"
results["message"] = "User not logged in"
end
respond_with( results.to_json )
end
private
def get_ids
@vid_id = params[:videolink_id]
end
end
$("#likeVideo").click(function() {
$.ajax({
contentType: "application/json",
data: { game_id: game_id, videolink_id: current_video["videolink"]["id"] },
dataType: "json",
processData: false,
type: "POST",
url: "/likes/" + game_id,
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Http-Method-Override", "PUT");
},
failure: function(data) {
console.log("Failed", data);
},
success: function(data) {
console.log("Success", data);
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment