У меня есть полиморф c Связь has_many с has_many, управляемая с помощью Active Admin. Есть две разные модели BlogArticle и MagazineArticle, которые имеют много авторов через таблицу авторинга. Ассоциация работает правильно, но мне нужно создать какой-то ввод в активном администраторе, который позволит администратору указать порядок появления авторов для любой отдельной статьи.
Итак, цель состоит в том, чтобы получить BlogArticle и Magazine Article имеет много авторов со своим заказом.
Я могу использовать атрибут позиции, помещенный в таблицу авторинга, но как мы можем управлять им в Active Admin?
В данный момент мое поле ввода в MagazineArticle и BlogArticle:
f.input :authors,
label: "Autori",
as: :select, multiple: true,
collection: Author.all.collect {|item| [item.full_name, item.id] }
end
этот «выбор» помещает авторов, упорядоченных updated_at объекта author (не объекта authoring). Этот отбор происходит из камня под названием activeadmin-addons, и он идеально подходит для нас, но я могу принять и другой способ продолжить.
модели:
class Authoring < ApplicationRecord
belongs_to :author
belongs_to :authorable, :polymorphic => true
default_scope {order(position: :asc)}
end
class Author < ApplicationRecord
has_many :authorings
has_many :blog_articles, :through => :authorings,
:source => :authorable,
:source_type => "BlogArticle"
has_many :magazine_articles, :through => :authorings,
:source => :authorable,
:source_type => "MagazineArticle"
end
class BlogArticle < ApplicationRecord
has_many :authorings, :as => :authorable, dependent: :destroy
has_many :authors, :through => :authorings
end
class MagazineArticle < ApplicationRecord
has_many :authorings, :as => :authorable, dependent: :destroy
has_many :authors, :through => :authorings
end
и его правильное добавление Авторы мне нужны, но явно без какого-либо упорядочения.
Как мне управлять позицией Авторинга в Active Admin?
------- РЕДАКТИРОВАТЬ ------ -
Я попробовал, как предложено @ Piers C (большое спасибо), использовать activeadmin_select_many драгоценный камень, который, кажется, соответствует моим потребностям, но это теперь несовместим с моей версией active_admin
Bundler could not find compatible versions for gem "activeadmin":
In snapshot (Gemfile.lock):
activeadmin (= 2.6.1)
In Gemfile:
activeadmin
activeadmin_select_many was resolved to 0.3.4, which depends on
activeadmin (~> 1.0)
Я пытался "обновить пакет", но ничего не поделать - большое количество несовместимостей
Bundler could not find compatible versions for gem "activeadmin":
In Gemfile:
activeadmin
activeadmin_select_many was resolved to 0.3.4, which depends on
activeadmin (~> 1.0)
Bundler could not find compatible versions for gem "activemodel":
In Gemfile:
carrierwave (~> 2.0) was resolved to 2.1.0, which depends on
activemodel (>= 5.0.0)
rails (~> 6.0.0) was resolved to 6.0.1.rc1, which depends on
activemodel (= 6.0.1.rc1)
web-console (>= 3.3.0) was resolved to 4.0.1, which depends on
activemodel (>= 6.0.0)
Bundler could not find compatible versions for gem "activerecord":
In Gemfile:
friendly_id was resolved to 5.3.0, which depends on
activerecord (>= 4.0.0)
rails (~> 6.0.0) was resolved to 6.0.1.rc1, which depends on
activerecord (= 6.0.1.rc1)
Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
bullet was resolved to 6.1.0, which depends on
activesupport (>= 3.0.0)
jbuilder (~> 2.7) was resolved to 2.10.0, which depends on
activesupport (>= 5.0.0)
rails (~> 6.0.0) was resolved to 6.0.1.rc1, which depends on
activesupport (= 6.0.1.rc1)
rename was resolved to 1.0.6, which depends on
activesupport
webpacker (~> 4.0) was resolved to 4.2.2, which depends on
activesupport (>= 4.2)
Bundler could not find compatible versions for gem "listen":
In Gemfile:
listen (>= 3.0.5, < 3.2)
spring-watcher-listen (~> 2.0.0) was resolved to 2.0.1, which depends on
listen (>= 2.7, < 4.0)
Bundler could not find compatible versions for gem "rails":
In Gemfile:
rails (~> 6.0.0)
rename was resolved to 1.0.6, which depends on
rails (>= 3.0.0)
Bundler could not find compatible versions for gem "railties":
In Gemfile:
activeadmin was resolved to 1.2.1, which depends on
railties (>= 4.2, < 5.2)
activeadmin_addons was resolved to 1.7.1, which depends on
railties
devise was resolved to 4.7.1, which depends on
railties (>= 4.1.0)
dotenv-rails was resolved to 2.7.5, which depends on
railties (>= 3.2, < 6.1)
rails (~> 6.0.0) was resolved to 6.0.1.rc1, which depends on
railties (= 6.0.1.rc1)
rails-i18n was resolved to 6.0.0, which depends on
railties (>= 6.0.0, < 7)
sass-rails (~> 5) was resolved to 5.1.0, which depends on
railties (>= 5.2.0)
web-console (>= 3.3.0) was resolved to 4.0.1, which depends on
railties (>= 6.0.0)
webpacker (~> 4.0) was resolved to 4.2.2, which depends on
railties (>= 4.2)