Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding authorization logic to votes

  • Loading branch information...
commit baf9c293aceeb4a3927e2a8f43489893acb504b8 1 parent c4be349
Russell authored
View
8 app/controllers/votes_controller.rb
@@ -10,15 +10,11 @@ def like
if !error and current_user and @voteable.present? and current_user.vote_for(@voteable)
success = "Thanks for your vote!"
format.html { flash[:success] = success; redirect_to params[:return_to] || @voteable }
- format.fbml { flash[:success] = success; redirect_to params[:return_to] || @voteable }
- format.json { render :json => { :msg => "#{@voteable.votes_tally} likes" }.to_json }
- format.fbjs { render :json => { :msg => "#{@voteable.votes_tally} likes" }.to_json }
+ format.json { render :json => { :trigger_oauth => true, :msg => "#{@voteable.votes_tally} likes" }.to_json }
else
error ||= "Vote failed"
format.html { flash[:error] = error; redirect_to params[:return_to] || @voteable }
- format.fbml { flash[:error] = error; redirect_to params[:return_to] || @voteable }
- format.json { render :json => { :msg => error }.to_json }
- format.fbjs { render :text => { :msg => error }.to_json }
+ format.json { render :json => { :trigger_oauth => true, :msg => error }.to_json }
end
end
end
View
29 public/javascripts/application.js
@@ -119,20 +119,23 @@ $(function() {
data: "foo", // data has to be set to explicitly set the content type
dataType: "json",
success: function(data, status) {
- span.fadeOut("normal", function() {
- span.html(data.msg).fadeIn("normal");
- });
- },
- error: function(xhr, status, errorThrown) {
- var result = $.parseJSON(xhr.responseText);
- if (xhr.status == 401) {
- dialog_response(result.error, result.dialog);
- span.fadeOut("normal", function() {
- span.html(data.msg).fadeIn("normal");
+ span.fadeOut("normal", function() {
+ span.html(data.msg).fadeIn("normal");
+ });
+ if (data.trigger_oauth && data.trigger_oauth == true) {
+ window.location = '/oauth/new';
+ }
+ },
+ error: function(xhr, status, errorThrown) {
+ var result = $.parseJSON(xhr.responseText);
+ if (xhr.status == 401) {
+ dialog_response(result.error, result.dialog);
+ span.fadeOut("normal", function() {
+ span.html(data.msg).fadeIn("normal");
+ });
+ }
+ }
});
- }
- }
- });
});
$('.quick_post').click(function(event) {
Please sign in to comment.
Something went wrong with that request. Please try again.