Created
January 29, 2011 05:53
-
-
Save cbmeeks/801581 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
$("#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