班级测验:底部按钮显示有问题

This commit is contained in:
cxt 2017-03-24 18:36:51 +08:00
parent 2f5ee19737
commit 59b4bb22c4
2 changed files with 16 additions and 6 deletions

View File

@ -8,15 +8,25 @@ class Exercise < ActiveRecord::Base
has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过
# 课程消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
after_create :acts_as_course_message
after_save :acts_as_course_message
def acts_as_course_message
if self.course
if self.exercise_status == 2 #未发布
if self.exercise_status == 2 && self.course_messages.where(:status => 2).blank? #已发布
self.delay.send_exercise_message_delay
#self.course.members.each do |m|
self.course_messages << CourseMessage.create(:user_id => User.current.id, :course_id => self.course_id, :viewed => false,:status=>2)
#self.course_messages << CourseMessage.create(:user_id => User.current.id, :course_id => self.course_id, :viewed => false,:status=>2)
#end
# else
# self.course_messages.destroy_all 这里的destory_all值得商榷。因为我这里是通过status来控制不同的status的
else
#self.course_messages.destroy_all #这里的destory_all值得商榷。因为我这里是通过status来控制不同的status的
end
end
end
#测验通知delay
def send_exercise_message_delay
self.course.members.each do |m|
if m.user_id != self.user_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false ,:status=>2)
end
end
end

View File

@ -153,7 +153,7 @@
<%= render :partial => 'exercise/total_questions_score', :locals => {:exercise => exercise, :current_score => current_score} %>
</div>
<div class="ur_buttons" style="width: 297px;">
<div class="ur_buttons" style="width: 298px;">
<%= link_to "返回", exercise_index_path(:course_id => @course.id),:class => "btn_grey_64_width" %>
<a href="javascript:void(0)" onclick="send_exercise_to_course();" class="btn_green_64_width ml10 mr10">发送</a>
<% if exercise.exercise_status == 1 %>