Sinatra how to include more than one belongs_to JSON?

Viewed 22

I have 3 models first fight belongs to blue_fighter and red_fighter

class Fight < ActiveRecord::Base
belongs_to :blue_fighter
belongs_to :red_fighter
end

then my other 2 models are like this blue_fighters

class BlueFighter < ActiveRecord::Base
has_many :fights
has_many :red_fighters, through: :fights
end

red_fighters

class RedFighter < ActiveRecord::Base
has_many :fights
has_many :blue_fighters, through: :fights
end

Now in my application controller

class ApplicationController < Sinatra::Base
set :default_content_type, 'application/json'

get '/fights' do
    fights = Fight.all
    fights.to_json(include: :blue_fighter)
end



end

im only getting the :blue_fighters i want to include both the :blue_fighter and :red_fighter

i tried something like this it doesnt work

fights.to_json(include: :blue_fighter && :red_fighter)
0 Answers
Related