Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Show < ApplicationRecord
- has_many :seasons, dependent: :destroy
- has_many :actors, dependent: :destroy
- has_many :staff, dependent: :destroy
- accepts_nested_attributes_for :seasons, allow_destroy: true
- accepts_nested_attributes_for :actors, allow_destroy: true
- accepts_nested_attributes_for :staff, allow_destroy: true
- end
- class Episode < ApplicationRecord
- belongs_to :show
- end
- class Actor < ApplicationRecord
- belongs_to :show
- belongs_to :episode
- end
- class Summary < ApplicationRecord
- has_many :episodes
- has_many :shows, through: :episodes
- has_many :actors, through: :episodes
- end
- class ShowsController < ApplicationController
- def create
- @show.episodes.build
- @show.episodes.build.summary.build
- end
- private
- def show_params
- params.require(:show).permit(:id, episodes_attributes: [:id, :show_id, :_destroy, summary_attributes:[:show_id, actor_id, :_destroy]]
- end
- end
- end
Add Comment
Please, Sign In to add comment