课程删除功能
This commit is contained in:
parent
42f5b86d95
commit
916d99be82
|
@ -775,7 +775,18 @@ class CoursesController < ApplicationController
|
||||||
#删除课程
|
#删除课程
|
||||||
#删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到
|
#删除课程只是将课程的is_deleted状态改为false,is_deleted为false状态的课程只有管理员可以看到
|
||||||
def destroy
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Course < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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 :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 :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表
|
belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表
|
||||||
|
@ -86,7 +86,8 @@ class Course < ActiveRecord::Base
|
||||||
'is_public',
|
'is_public',
|
||||||
'description',
|
'description',
|
||||||
'class_period',
|
'class_period',
|
||||||
'open_student'
|
'open_student',
|
||||||
|
'is_delete'
|
||||||
|
|
||||||
acts_as_customizable
|
acts_as_customizable
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ class Course < ActiveRecord::Base
|
||||||
scope :active, lambda { where(:status => STATUS_ACTIVE) }
|
scope :active, lambda { where(:status => STATUS_ACTIVE) }
|
||||||
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
|
||||||
scope :all_public, lambda { where(:is_public => true) }
|
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|
|
scope :allowed_to, lambda {|*args|
|
||||||
user = User.current
|
user = User.current
|
||||||
permission = nil
|
permission = nil
|
||||||
|
|
|
@ -67,6 +67,9 @@
|
||||||
<td class="center">
|
<td class="center">
|
||||||
<%= format_date(course.created_at) %>
|
<%= format_date(course.created_at) %>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="buttons">
|
||||||
|
<%= link_to(l(:button_delete), course_path(course), :method => :delete, :class => 'icon icon-del', :onClick=>"delcfm()" ) %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class AddIsDeleteToCourses < ActiveRecord::Migration
|
class AddIsDeleteToCourses < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
add_column :courses, :is_delete, :integer
|
add_column :courses, :is_delete, :integer, :default => 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue