点赞功能
This commit is contained in:
parent
70f14f851d
commit
4d43cd2765
|
@ -2,8 +2,8 @@ class StudentWorkController < ApplicationController
|
|||
layout "base_courses"
|
||||
include StudentWorkHelper
|
||||
before_filter :find_homework, :only => [:new, :index, :create]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score]
|
||||
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score]
|
||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
||||
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
|
@ -166,6 +166,22 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
#为作品点赞
|
||||
def praise_student_work
|
||||
pt = PraiseTread.new
|
||||
pt.user_id = User.current.id
|
||||
pt.praise_tread_object_id = @work.id
|
||||
pt.praise_tread_object_type = "StudentWork"
|
||||
pt.praise_or_tread = 1
|
||||
if pt.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
#获取作业
|
||||
def find_homework
|
||||
|
|
|
@ -50,4 +50,14 @@ module StudentWorkHelper
|
|||
end
|
||||
result
|
||||
end
|
||||
|
||||
#获取赞的总数
|
||||
def praise_homework_count obj_id
|
||||
PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count
|
||||
end
|
||||
|
||||
#判断指定用户是不是已经赞过该作业
|
||||
def is_praise_homework user_id, obj_id
|
||||
PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty?
|
||||
end
|
||||
end
|
|
@ -15,8 +15,8 @@
|
|||
</li>
|
||||
<% end%>
|
||||
<% if (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3) && @work.user != User.current%> <!-- 普通作业或者编程作业,或者是匿评结束阶段,显示点赞按钮 -->
|
||||
<li class="fr" >
|
||||
<a href="javascript:void(0);" class="orange_btn" style="font-size:12px;" >赞(10)</a>
|
||||
<li class="fr" id="student_work_praise_<%= @homework.id%>">
|
||||
<%= render :partial => 'student_work_praise' %>
|
||||
</li>
|
||||
<% end%>
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<% if is_praise_homework User.current.id,@homework.id %>
|
||||
<%= link_to "赞(#{praise_homework_count @homework.id})",praise_student_work_student_work_path(@homework), :remote => true,:class => 'orange_btn', :style => 'font-size:12px;'%>
|
||||
<% else %>
|
||||
<%= link_to "赞(#{praise_homework_count @homework.id})","javascript:void(0)",:class => 'grey_btn', :style => 'font-size:12px;'%>
|
||||
<% end %>
|
|
@ -0,0 +1 @@
|
|||
$('#student_work_praise_<%= @homework.id%>').html('<%= escape_javascript(render :partial => 'student_work_praise')%>');
|
|
@ -94,6 +94,7 @@ RedmineApp::Application.routes.draw do
|
|||
resources :student_work do
|
||||
member do
|
||||
post 'add_score'
|
||||
get 'praise_student_work'
|
||||
end
|
||||
collection do
|
||||
post 'add_score_reply'
|
||||
|
|
Loading…
Reference in New Issue