|
|
|
@ -288,11 +288,11 @@ class CoursesController < ApplicationController
|
|
|
|
|
inform = @course.informs.find_by(id: params[:inform_id])
|
|
|
|
|
next_inform = inform.next_inform
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
if next_inform
|
|
|
|
|
if next_inform.blank?
|
|
|
|
|
render_error('已经到达最顶部')
|
|
|
|
|
else
|
|
|
|
|
inform.update_attribute(:position, (position + 1))
|
|
|
|
|
next_inform.update_attribute(:position, last_inform.position - 1)
|
|
|
|
|
inform.update_attribute(:position, (inform.position + 1))
|
|
|
|
|
next_inform.update_attribute(:position, inform.position - 1)
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -302,11 +302,11 @@ class CoursesController < ApplicationController
|
|
|
|
|
inform = @course.informs.find_by(id: params[:inform_id])
|
|
|
|
|
last_inform = inform.last_inform
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
if last_inform
|
|
|
|
|
if last_inform.blank?
|
|
|
|
|
render_error('已经到达最底部')
|
|
|
|
|
else
|
|
|
|
|
inform.update_attribute(:position, (position - 1))
|
|
|
|
|
last_inform.update_attribute(:position, last_inform.position + 1)
|
|
|
|
|
inform.update_attribute(:position, (inform.position - 1))
|
|
|
|
|
last_inform.update_attribute(:position, inform.position + 1)
|
|
|
|
|
render_ok
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -317,7 +317,7 @@ class CoursesController < ApplicationController
|
|
|
|
|
inform = Inform.new(container: @course)
|
|
|
|
|
inform.name = params[:name]
|
|
|
|
|
inform.description = params[:description]
|
|
|
|
|
inform.position = @course.informs.maximum(:position) + 1
|
|
|
|
|
inform.position = @course.informs.maximum(:position).to_i + 1
|
|
|
|
|
inform.save!
|
|
|
|
|
normal_status("创建成功")
|
|
|
|
|
end
|
|
|
|
|