У меня есть форма, которая обрабатывает четыре разных типа фасетов одной формы. В моем столбце SQL у меня есть четыре различных атрибута.
Только у одного из них будут данные.
Distribution =>
zip_code: nil
me_topic: nil
sex: nil
age: nil
Чтобы различать их, я хотел создать оператор case и добавить атрибут dynamic в вызов create:
@type = case params[:type]
when "zip" then ":zip_code"
when "interest" then ":me_topic"
when "sex" then ":sex"
when "age" then ":age"
end
@cur_item = Distribution.new(@type => params[:value])
# Unfortunately, this is not the proper way to create a dynamic attribute
@distribution = @email.distributions.create(params[:distributions])
Каков правильный синтаксис для завершения этого оператора?