加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActiveAdmin / Formtastic可排序has_many通过

发布时间:2020-12-16 21:07:23 所属栏目:百科 来源:网络整理
导读:我可能会遗漏一些基本的东西,但我似乎无法让ActiveAdmin使用可排序的has_many通过关系,能够创建新记录. 所以给出以下模型 class User ActiveRecord::Base has_many :user_videos has_many :videos,through: :user_videos accepts_nested_attributes_for :use
我可能会遗漏一些基本的东西,但我似乎无法让ActiveAdmin使用可排序的has_many通过关系,能够创建新记录.

所以给出以下模型

class User < ActiveRecord::Base

  has_many :user_videos
  has_many :videos,through: :user_videos

  accepts_nested_attributes_for :user_videos
  accepts_nested_attributes_for :videos

  ...
end

class UserVideo < ActiveRecord::Base

  belongs_to :user
  belongs_to :video

  accepts_nested_attributes_for :video

end

class Video < ActiveRecord::Base

  has_many :user_videos
  has_many :users,through: :user_videos

  ...
end

(我承认我在某种程度上抛弃accepted_nested_attributes_for,希望有些东西可行)

Active Admin设置就像这样(当然是WIP):

f.inputs "User" do
  f.has_many :user_videos,heading: 'Videos',sortable: :order,allow_destroy: true,new_record: 'New Record' do |v|
    v.inputs for: :video do |video|
      video.input :video_url
    end
  end
  f.has_many :videos,new_record: 'New Video' do |v|
    v.input :video_url
  end
end

f.actions

关于:user_videos关联的第一个has_many似乎不呈现任何输入.如果那里有记录,我可以看到video.input:video_url实际上是返回带有标签和输入的li标签,但是没有任何内容呈现给页面.对于新记录,整个v.inputs位不会运行(我是否需要首先以某种方式创建子记录?).

第二个has_many将起作用,你将能够添加记录,并更新现有记录,但是由于订单列在UserVideos模型上,因此无法排序.我把它作为插图而不是任何东西.

如果有人有任何指示,他们将非常感激.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读