Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. { tags: [
  2. { "id": 1,
  3. "name": Mens,
  4. "items": [
  5. {
  6. "id": 1,
  7. "name": shirts,
  8. "liking_users": [
  9. {
  10. "id": 1,
  11. "name": Tom
  12. },
  13. {
  14. "id": 2,
  15. "name": Steve
  16. }
  17. ]
  18. }
  19. ]
  20. }
  21. ]
  22. }
  23.  
  24. class Tag < ActiveRecord::Base
  25. has_many :items
  26. end
  27.  
  28. class Item < ActiveRecord::Base
  29. has_many :likes, dependent: :destroy
  30. has_many :liking_users, through: :likes, source: :user
  31. end
  32.  
  33. class User < ActiveRecord::Base
  34. has_many :likes, dependent: :destroy
  35. has_many :like_items, through: :likes, source: :item
  36. end
  37.  
  38. class Like < ActiveRecord::Base
  39. belongs_to :item
  40. belongs_to :user
  41. end
  42.  
  43. module API
  44. module V1
  45. class Tags < Grape::API
  46. resource :tags do
  47.  
  48.    desc 'GET /api/v1/tags/:id'
  49.     params do
  50.     requires :id, type: Integer, desc: "Tag id."
  51.    end
  52.     get '/:id' do
  53.     tag = Tag.find(params[:id])
  54.     @tag = tag.items. #この行をどう書けばいいかわからないです、、
  55.    end
  56. end
  57. end
  58. end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement