Simple example, I have two Models relation with has_many_belongs associations
How to render with to_json function users_count?
class Place < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :places
end
places = Place.all
render json: {desc:true, status: 1, data: places}.to_json(:include => [:users])
output: data[
{
place_id: 1,
users[]
}
How can I output like this:
output: data[
{
place_id: 1,
users_count: 10
}
I am beginner, please can you help? )