From 093574ebef151e68cc1910b537e00b5f97633de9 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 13 Jan 2016 19:16:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=AF=BE=E7=A8=8B=E8=AE=A8?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E5=8A=A8=E6=80=81=E7=9A=84=E7=82=B9=E8=B5=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/praise_tread_controller.rb | 18 +++++++++++++----- app/views/praise_tread/_praise.html.erb | 4 ++-- app/views/praise_tread/praise_minus.js.erb | 2 +- app/views/praise_tread/praise_plus.js.erb | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index be8cbc9a6..36d9251e1 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -9,7 +9,13 @@ class PraiseTreadController < ApplicationController if @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first end + @activity = false if request.get? + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end @obj_id = params[:obj_id] @obj_type = params[:obj_type] #@horizontal = params[:horizontal].downcase == "false" ? false:true @@ -17,13 +23,12 @@ class PraiseTreadController < ApplicationController unless @obj.author_id == User.current.id praise_tread_plus(@obj_type,@obj_id,1) end - @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @type = params[:type] if params[:type] - end + end end def praise_minus @obj = nil + @activity = false if request.get? #@obj = params[:obj] # 传的是对象,最后变成id了 @obj_id = params[:obj_id] @@ -43,8 +48,11 @@ class PraiseTreadController < ApplicationController end #@obj = User.find_by_id(@obj) @obj = find_object_by_type_and_id(@obj_type,@obj_id) - @user_activity_id = params[:user_activity_id] if params[:user_activity_id] - @type = params[:type] if params[:type] + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end respond_to do |format| format.js end diff --git a/app/views/praise_tread/_praise.html.erb b/app/views/praise_tread/_praise.html.erb index 9059f1628..b1a14bb81 100644 --- a/app/views/praise_tread/_praise.html.erb +++ b/app/views/praise_tread/_praise.html.erb @@ -1,7 +1,7 @@ <% if PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",activity.id,activity.class.to_s,User.current.id).empty? %> - + <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> <% else %> - + <%= get_praise_num(activity) > 0 ? "(#{get_praise_num(activity)})" : "" %> <% end %> \ No newline at end of file diff --git a/app/views/praise_tread/praise_minus.js.erb b/app/views/praise_tread/praise_minus.js.erb index 63efe303c..63d30d3a5 100644 --- a/app/views/praise_tread/praise_minus.js.erb +++ b/app/views/praise_tread/praise_minus.js.erb @@ -1,4 +1,4 @@ -<% if @user_activity_id %> +<% if @activity %> <% if @type.to_s == 'activity' %> $('#praise_count_<%=@user_activity_id %>').html('<%= j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); <% else %> diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index 30b28fff1..ce14ec1f8 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -2,7 +2,7 @@ $('#praise_tread_<%= @obj.id %>').html('<%= j( render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} )%>'); -<% elsif @user_activity_id %> +<% elsif @activity %> <% if @type.to_s == 'activity' %> $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); <% else %>