Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
d50063c786
@ -1,10 +1,17 @@
|
|||||||
class Users::ApplyProfessionalAuthForm
|
class Users::ApplyProfessionalAuthForm
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image
|
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image, :attachment_ids
|
||||||
|
|
||||||
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
||||||
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
|
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
|
||||||
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
|
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
|
||||||
validates :extra, presence: true
|
validates :extra, presence: true
|
||||||
|
validate :validate_attachment_ids
|
||||||
|
|
||||||
|
def validate_attachment_ids
|
||||||
|
unless attachment_ids.is_a?(Array) || attachment_ids.length != 1
|
||||||
|
raise("图片参数不对")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
@ -0,0 +1,17 @@
|
|||||||
|
class AddPositionForInforms < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :informs, :position, :integer, :default => 1
|
||||||
|
|
||||||
|
course_ids = Inform.where(container_type: 'Course').pluck(:container_id).uniq
|
||||||
|
courses = Course.where(id: course_ids)
|
||||||
|
|
||||||
|
courses.find_each do |course|
|
||||||
|
next if course.informs.count == 1
|
||||||
|
informs = course.informs.order("created_at asc")
|
||||||
|
informs.each_with_index do |inform, index|
|
||||||
|
inform.update_attribute(:position, index+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue