课程删除功能

This commit is contained in:
huang 2015-12-08 16:45:26 +08:00
parent 42f5b86d95
commit 916d99be82
4 changed files with 19 additions and 4 deletions

View File

@ -775,7 +775,18 @@ class CoursesController < ApplicationController
#删除课程
#删除课程只是将课程的is_deleted状态改为falseis_deleted为false状态的课程只有管理员可以看到
def destroy
@course.update_attributes(:is_delete => true)
@course = nil
redirect_to user_url(User.current)
end
# 恢复已删除的课程
def recovery
if User.current.admin?
@course.update_attributes(:is_delete => false)
else
return 403
end
end
private

View File

@ -20,7 +20,7 @@ class Course < ActiveRecord::Base
end
end
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name
attr_accessible :code, :extra, :name, :state, :tea_id, :time , :location, :state, :term, :password,:is_public,:description,:class_period, :open_student, :enterprise_name, :is_delete
#belongs_to :project, :class_name => 'Course', :foreign_key => :extra, primary_key: :identifier
belongs_to :teacher, :class_name => 'User', :foreign_key => :tea_id # 定义一个方法teacher该方法通过tea_id来调用User表
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school该方法通过school_id来调用School表
@ -86,7 +86,8 @@ class Course < ActiveRecord::Base
'is_public',
'description',
'class_period',
'open_student'
'open_student',
'is_delete'
acts_as_customizable
@ -94,7 +95,7 @@ class Course < ActiveRecord::Base
scope :active, lambda { where(:status => STATUS_ACTIVE) }
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
scope :all_public, lambda { where(:is_public => true) }
scope :visible, lambda {|*args| where(Course.visible_condition(args.shift || User.current, *args)) }
scope :visible, lambda {|*args| where(Course.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) }
scope :allowed_to, lambda {|*args|
user = User.current
permission = nil

View File

@ -67,6 +67,9 @@
<td class="center">
<%= format_date(course.created_at) %>
</td>
<td class="buttons">
<%= link_to(l(:button_delete), course_path(course), :method => :delete, :class => 'icon icon-del', :onClick=>"delcfm()" ) %>
</td>
</tr>
<% end %>
</tbody>

View File

@ -1,5 +1,5 @@
class AddIsDeleteToCourses < ActiveRecord::Migration
def change
add_column :courses, :is_delete, :integer
add_column :courses, :is_delete, :integer, :default => 0
end
end