Twig

Joined

300 Experience
2 Lessons Completed
0 Questions Solved

Activity

I'm using accepts_nested_attributes_for in one of my models and want to handle the nested attribute (photos) in my Administrate form. It doesn't appear that administrate handles the nested association out-the-box. I've tried using https://github.com/nickcharlton/administrate-field-nested_has_many but I get the following error:

uninitialized constant Administrate::Field::NestedHasMany

Perhaps it's not compatible with the Jumpstart Administrate version?

What's the preferred approach for handling accepts_nested_attributes_for with Administrate, can someone advise?

I need some help figuring out how I should associate my models.

I have three models:

class Series < ApplicationRecord
  has_many :modules
  has_many :episodes
end
class Module < ApplicationRecord
  belongs_to :series
  has_many :episodes
end
class Episode < ApplicationRecord
  belongs_to :modules, optional: true
  belongs_to :series, optional: true
end

I need to be able to manually specify the order of the following has_many relationships:

  1. Module in a Series
  2. Episode in a Module
  3. Episode in a Series.

I believe I need a has_many, through:, possibly 3 of them? One for each relationship, so

class Series < ApplicationRecord
  has_many :modules, through: :module_series
  has_many :episodes, through: :episode_series
end
class Module < ApplicationRecord
  belongs_to :series
  has_many :episodes, through: module_episode
end

Am i approaching this the correct way?

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.