我有包含序列化属性主题的Happening模型:
class Happening < ApplicationRecord
serialize :topics
end
然后在控制器中,当我创建新事件时,我使用split方法来分隔主题:
@happening = Happening.new(happening_params)
@happening.topics = @happening.topics.split(',').map(&:strip) # separate
if @happening.save
但也许这不是个好主意?最好的方法是什么?