正如我最初所怀疑的那样,问题不在于我的工厂。
我在 section.rb 上有一个 before_create 方法,它将数组转换为字符串。我改变了工作方式并解决了问题。
前:
class Section < ActiveRecord::Base
serialize :days_of_week
before_create :array_to_s
belongs_to :course
belongs_to :teacher
belongs_to :semester
has_many :student_section_enrollments
has_many :students, :through => :student_section_enrollments
WEEKDAYS = ["M", "TU", "W", "TH", "F"]
TIME_BLOCKS = ["7:45-9:15", "9:30-11:00"]
def set_next_section_number(semester)
self.section_number = semester.sections.count + 1
end
def current_semester_sections
@current_sections = Section.where("description LIKE ?", current_semester)
end
private
def array_to_s
self.days_of_week = self.days_of_week.reject!(&:empty?)
self.days_of_week = self.days_of_week.join(', ')
end
结尾
后:
class Section < ActiveRecord::Base
serialize :days_of_week, Array
before_save :remove_empty_days_of_week
belongs_to :course
belongs_to :teacher
belongs_to :semester
has_many :student_section_enrollments
has_many :students, :through => :student_section_enrollments
WEEKDAYS = ["M", "TU", "W", "TH", "F"]
TIME_BLOCKS = ["7:45-9:15", "9:30-11:00"]
def set_next_section_number(semester)
self.section_number = semester.sections.count + 1
end
def current_semester_sections
@current_sections = Section.where("description LIKE ?", current_semester)
end
def days_of_week_string
days_of_week.join(', ')
end
private
def remove_empty_days_of_week
if self.days_of_week.present?
self.days_of_week.reject!(&:empty?)
end
end
end