From f5ff1734750e756fdbe382140fca698f0a8389fb Mon Sep 17 00:00:00 2001 From: Bruno Azisaka Maciel Date: Sun, 17 Oct 2010 21:22:15 -0200 Subject: [PATCH] Fix for like's messages --- app/controllers/likes_controller.rb | 4 +++- app/views/templates/_like_status.html.haml | 2 +- app/views/templates/show.html.haml | 11 ++++++----- public/javascripts/application.js | 7 +++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 8d96e7d..09d3181 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -1,12 +1,14 @@ class LikesController < ApplicationController include ActionView::Helpers::TextHelper + include TemplatesHelper + before_filter :authenticate_githubber! def create template = Template.find(params[:template_id]) like = current_githubber.like_it template if like.persisted? - render :json => { :status => pluralize(template.likes.count, "person like it", "people like it") } + render :json => { :status => like_counter(template) } else render :json => {}, :status => 406 end diff --git a/app/views/templates/_like_status.html.haml b/app/views/templates/_like_status.html.haml index 36f0e27..2d732b3 100644 --- a/app/views/templates/_like_status.html.haml +++ b/app/views/templates/_like_status.html.haml @@ -3,7 +3,7 @@ %p= like_counter(template) - if githubber_signed_in? && !current_githubber.liked?(template) .link-default.rounded-all - = link_to 'I like it', template_likes_path(template), :method => :POST, :id => 'like_button', :remote => true + = link_to 'I like it', template_likes_path(template), :method => :post, :id => 'like_button', :remote => true, "data-type" => "html" - if !githubber_signed_in? .link-default.rounded-all diff --git a/app/views/templates/show.html.haml b/app/views/templates/show.html.haml index 3d2b90a..57f41f5 100644 --- a/app/views/templates/show.html.haml +++ b/app/views/templates/show.html.haml @@ -66,11 +66,12 @@ #commentaries %h3 Comments - - if @template.commentaries.size > 0 - - @template.commentaries.reverse.each do |commentary| - .commentary= render :partial => "commentary", :object => commentary - - else - %p.notice Be the first to comment about this template! + .comments-list + - if @template.commentaries.size > 0 + - @template.commentaries.reverse.each do |commentary| + .commentary= render :partial => "commentary", :object => commentary + - else + %p.notice Be the first to comment about this template! - if current_githubber - semantic_form_for @commentary, :url => template_commentaries_path(@template), :remote => true, :html => { "data-type" => "html" } do |form| diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 8f03174..4782001 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -15,6 +15,7 @@ var Application = { }); } }); + $(".delete-template") .bind('ajax:success', onSuccess); $('.unlike-template').bind('ajax:success', function() { @@ -32,17 +33,19 @@ var Application = { } }); }); - $(".delete-template").bind('ajax:success', onSuccess); + + $(".delete-template").bind('ajax:success', onSuccess); } }, commentaryCreation: function(){ $("#new_commentary") .bind('ajax:loading', function(rawResponse, msg) { + $("#commentaries .notice").fadeOut('fast'); $("#commentaries").parent().find('.error').remove(); }) .bind('ajax:success', function(rawResponse,msg) { var div = $("
").addClass('commentary').css("display", "none").html(msg); - $('#commentaries').prepend(div); + $('.comments-list').prepend(div); $('#commentary_commentary').val(''); div.slideDown(); }).bind('ajax:failure', function(rawResponse, msg){