Ruby on rails Rails-嵌套表单

Ruby on rails Rails-嵌套表单,ruby-on-rails,ruby,nested-forms,Ruby On Rails,Ruby,Nested Forms,我对嵌套表单有问题,我是rails新手,所以可能我做错了什么,所以我希望您能帮助我。提前谢谢 我有一个模型Poi兴趣点,一个模型Poi描述和一个模型描述类型。Poi实例具有许多Poi描述,而DescriptionType具有许多Poi描述。我想要的是:当我创建一个新的Poi时,我想要为它创建多个描述。一个描述有一个与其关联的类别,每个类别只能有一个描述X:10个类别=10个描述。这是我的代码: Poi模型 POI描述模型 描述类型模型 Poi控制器 路线 Poi_形式 现在,问题来了。每次尝试创

我对嵌套表单有问题,我是rails新手,所以可能我做错了什么,所以我希望您能帮助我。提前谢谢

我有一个模型Poi兴趣点,一个模型Poi描述和一个模型描述类型。Poi实例具有许多Poi描述,而DescriptionType具有许多Poi描述。我想要的是:当我创建一个新的Poi时,我想要为它创建多个描述。一个描述有一个与其关联的类别,每个类别只能有一个描述X:10个类别=10个描述。这是我的代码:

Poi模型

POI描述模型

描述类型模型

Poi控制器

路线

Poi_形式

现在,问题来了。每次尝试创建新Poi时,我都会出现以下错误: 有人知道为什么会这样吗?谢谢


附言:很抱歉发了这么长的帖子:

我找到了解决办法。在使用Poi描述模型之前,我在Poi模型上有一个属性“description”,并且我对该属性进行了验证。当我更改模型时,我忘记删除验证,这就是我问题的根源

has_many :poi_descriptions
accepts_nested_attributes_for :poi_descriptions
belongs_to :poi
belongs_to :description_type
has_many :poi_descriptions
def new
  @poi = Poi.new
  @poi.poi_descriptions.build
  @availableType = DescriptionType.where.not(id: @poi.poi_descriptions.pluck(:description_type_id))
end

def poi_params
  params.require(:poi).permit(:name, :image, :longitude, :latitude, :monument_id, :beacon_id, poi_descriptions_attributes: [:description, :description_type_id, :id])
end
resources :pois do
  resources :poi_descriptions
end
resources :description_types
<%= form_with model: @poi do |f| %>
...
  <%= f.fields_for :poi_descriptions do |p| %>
    <%= p.collection_select :description_type_id, @availableType,:id,:name %>
    <%= p.text_area :description %>
  <% end %>
...
create_table "description_types", force: :cascade do |t|
  t.string "name"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
end

create_table "poi_descriptions", force: :cascade do |t|
  t.text "description"
  t.bigint "poi_id"
  t.bigint "description_type_id"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.index ["description_type_id"], name: "index_poi_descriptions_on_description_type_id"
  t.index ["poi_id"], name: "index_poi_descriptions_on_poi_id"
end

create_table "pois", id: :serial, force: :cascade do |t|
  t.text "name"
  t.float "longitude"
  t.float "latitude"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.integer "monument_id"
  t.integer "beacon_id"
  t.string "image_file_name"
  t.string "image_content_type"
  t.integer "image_file_size"
  t.datetime "image_updated_at"
  t.index ["beacon_id"], name: "index_pois_on_beacon_id"
  t.index ["monument_id"], name: "index_pois_on_monument_id"
end