主动管理嵌套

时间:2018-11-15 17:00:53

标签: ruby-on-rails ruby sqlite activeadmin

我有两个模型系列和情节。当我在Active Admin中单击新系列时,它仅显示按钮“添加新情节”,如何为系列添加输入,而且当我单击“编辑”时也会出现错误

ActiveRecord::StatementInvalid in Admin::Series#edit
SQLite3::SQLException: no such column: episodes.serie_id: SELECT "episodes".* FROM "episodes" WHERE "episodes"."serie_id" = ?

我的模型,在serie.rb

class Serie < ApplicationRecord
    has_many :episodes
    accepts_nested_attributes_for :episodes
end

在Episode.rb

class Episode < ApplicationRecord
    belongs_to :serie, optional: true
end

在admin / series.rb

ActiveAdmin.register Serie do
  permit_params :title, :desc, :year, :img

  index do
    column :id
    column :title
    column :year
    actions
    end

  form do |f|
    f.inputs "Details" do
      f.title
    end

    f.has_many :episodes do |episode|
      episode.inputs "Episodes" do
      episode.input :title
      end
    end
  end
end

0 个答案:

没有答案