Postgresql 如何在表单中使用hstore数据类型字段并将其存储在Rails 4的数据库中?

Postgresql 如何在表单中使用hstore数据类型字段并将其存储在Rails 4的数据库中?,postgresql,ruby-on-rails-4,hstore,Postgresql,Ruby On Rails 4,Hstore,我有以下要求:模型称为医学模型;它有医生型和治疗型;一个医疗模型可以选择多种医生类型和治疗类型 我试图避免为医生类型和治疗类型创建模型。它们基本上是应用程序向其用户提供的集合。我正在尝试将它们作为hstore字段存储在医疗模型上 我做了以下的 添加了对hstore的迁移: class AddHstore < ActiveRecord::Migration def up enable_extension :hstore end def down

我有以下要求:模型称为医学模型;它有医生型和治疗型;一个医疗模型可以选择多种医生类型和治疗类型

我试图避免为医生类型和治疗类型创建模型。它们基本上是应用程序向其用户提供的集合。我正在尝试将它们作为hstore字段存储在医疗模型上

我做了以下的

添加了对hstore的迁移:

   class AddHstore < ActiveRecord::Migration 
    def up
     enable_extension :hstore
    end

    def down
     disable_extension :hstore
    end
  end
然后将新字段添加到表单中:

<%= simple_form_for([@case, @medical]) do |f| %>
    <%= f.input :total_med_bills %>
    <%= f.input :length_of_treatment %>
    <%= f.simple_fields_for :data do |d| %>
      <%= d.input :doctor_type, as: :check_boxes, collection: Medical::DOCTOR_TYPE %>
      <%= d.input :treatment_type, as: :check_boxes, collection: Medical::TREATMENT_TYPE %> 
    <% end %>
    <%= f.input :injury_summary %>
...
当我查看控制台时,我发现数据哈希不是空的:

Unpermitted parameters: doctor_type, treatment_type
..."length_of_treatment"=>"", "data"=>{"doctor_type"=>["MD", "Specialist", ""], "treatment_type"=>["Meds", "Other", ""]}, "injury_summary"=>"",...

由于强参数不允许在强参数中使用标量值…我最终执行了以下操作

强参数:

... :data => [:doctor_type => [], :treatment_type => []] ...

doctor\u type
treatment\u type
键可以有多个值。

您对所讨论的控制器的强参数设置是什么?@muistooshort,我已经从控制器添加了强参数
Unpermitted parameters: doctor_type, treatment_type
..."length_of_treatment"=>"", "data"=>{"doctor_type"=>["MD", "Specialist", ""], "treatment_type"=>["Meds", "Other", ""]}, "injury_summary"=>"",...
... :data => [:doctor_type => [], :treatment_type => []] ...