课程删除功能
This commit is contained in:
parent
42f5b86d95
commit
916d99be82
|
@ -775,7 +775,18 @@ class CoursesController < ApplicationController
|
|||
#删除课程
|
||||
#删除课程只是将课程的is_deleted状态改为false,is_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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue