Guest User

Untitled

a guest
Dec 11th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. ChefPosition (Executive, Sous, etc...)
  2. Skills (Creativity, speed, quality)
  3.  
  4. ChefPositionSkill (chef_position_id, skill_id)
  5.  
  6. ChefPositionSkillController < ApplicationController
  7.  
  8. def index
  9. @ChefPositionSkills = Skill.where(:chef_position => params[:chef_position_id]
  10. render json: @ChefPositionSkills, status: status
  11. end
  12. end
  13.  
  14. chef_positions
  15. * id
  16. * name
  17. * ...
  18.  
  19. skills
  20. * id
  21. * name
  22. * ...
  23.  
  24. chef_position_skills
  25. * id
  26. * chef_position_id
  27. * skill_id
  28.  
  29. class ChefPosition < ApplicationRecord
  30. has_many :chef_position_skills
  31. has_many :skills, through: :chef_position_skills
  32. end
  33.  
  34. class Skill < ApplicationRecord
  35. has_many :chef_position_skills
  36. has_many :chef_positions, through: :chef_position_skills
  37. end
  38.  
  39. class ChefPositionSkill < ApplicationRecord
  40. belongs_to :chef_position
  41. belongs_to :skill
  42. end
  43.  
  44. resources :chef_positions, only: [] do
  45. resources :chef_position_skills, only: [:index]
  46. end
  47.  
  48. class ChefPositionSkillsController < ApplicationController
  49. def index
  50. chef_position = ChefPosition.find(params[:chef_position_id])
  51. render json: chef_position.chef_position_skills
  52. end
  53. end
Add Comment
Please, Sign In to add comment