Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { tags: [
- { "id": 1,
- "name": Mens,
- "items": [
- {
- "id": 1,
- "name": shirts,
- "liking_users": [
- {
- "id": 1,
- "name": Tom
- },
- {
- "id": 2,
- "name": Steve
- }
- ]
- }
- ]
- }
- ]
- }
- class Tag < ActiveRecord::Base
- has_many :items
- end
- class Item < ActiveRecord::Base
- has_many :likes, dependent: :destroy
- has_many :liking_users, through: :likes, source: :user
- end
- class User < ActiveRecord::Base
- has_many :likes, dependent: :destroy
- has_many :like_items, through: :likes, source: :item
- end
- class Like < ActiveRecord::Base
- belongs_to :item
- belongs_to :user
- end
- module API
- module V1
- class Tags < Grape::API
- resource :tags do
- desc 'GET /api/v1/tags/:id'
- params do
- requires :id, type: Integer, desc: "Tag id."
- end
- get '/:id' do
- tag = Tag.find(params[:id])
- @tag = tag.items. #この行をどう書けばいいかわからないです、、
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement