0
레일 방법 :레일 Rabl 보석 : 쿼리 아이 부모 ID를 기반으로
def index
user = Users.find(params[:user_id])
@countries = user.countries
@cities = user.cities
end
국가 모델 has_many : 도시
도시 모델 belongs_to : 국가
사용자가 특정 국가와 특정에 액세스 할 수 있습니다 도시
해당 json.rabl 파일 :
object false
child @countries do
child @cities.where(country_name: country.name) do
attributes :name, :coordinates
end
end
내 질문에 대한 child @cities.where(country_name: country.name)
내 목표는 현재 상위 국가의 도시를 포함에 @cities을 필터링하는 것입니다.
rabl에서 가능합니까?