Guest User

Untitled

a guest
Oct 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. class Show < ApplicationRecord
  2. has_many :seasons, dependent: :destroy
  3. has_many :actors, dependent: :destroy
  4. has_many :staff, dependent: :destroy
  5.  
  6. accepts_nested_attributes_for :seasons, allow_destroy: true
  7. accepts_nested_attributes_for :actors, allow_destroy: true
  8. accepts_nested_attributes_for :staff, allow_destroy: true
  9. end
  10.  
  11. class Episode < ApplicationRecord
  12. belongs_to :show
  13. end
  14.  
  15. class Actor < ApplicationRecord
  16. belongs_to :show
  17. belongs_to :episode
  18. end
  19.  
  20. class Summary < ApplicationRecord
  21. has_many :episodes
  22. has_many :shows, through: :episodes
  23. has_many :actors, through: :episodes
  24. end
  25.  
  26. class ShowsController < ApplicationController
  27. def create
  28. @show.episodes.build
  29. @show.episodes.build.summary.build
  30. end
  31.  
  32. private
  33. def show_params
  34. params.require(:show).permit(:id, episodes_attributes: [:id, :show_id, :_destroy, summary_attributes:[:show_id, actor_id, :_destroy]]
  35. end
  36. end
  37. end
Add Comment
Please, Sign In to add comment