2013-04-12 4 views
-1

저는 Sinatra에서 빌드하고 API로 rabl을 사용하고 있습니다.노드 레이블이없는 자식 노드를 rabl에 렌더링

object @user 
    attributes :profile_photo => :profile_photo, :name => :first_name, :last_name =>  :last_name 
    child :addresses do 
    attributes :id 
    child :country do 
     attributes :name 
    end 
    end 

나는 다음과 같은 JSON 점점 오전 : 필요한 JSON이 Rabl 템플릿을 사용하여 일부 노드 에 라벨을 허용하지 데

{ 
user: { 
profile_photo: null, 
first_name: "John", 
last_name: "Doe", 
addresses: [ 
{ 
address: { 
id: 43, 
country: { 
name: "Iceland" 
} 
} 
}, 
{ 
address: { 
id: 44, 
country: { 
name: "Cambodia" 
} 
} 
}, 
{ 
address: { 
id: 45, 
country: { 
name: "North Korea" 
} 
} 
} 
] 
} 
} 

내가 싶어 원하는 것은 :

{ 
user: { 
profile_photo: null, 
first_name: "John", 
last_name: "Doe", 
addresses: [ 
{ 
{ 
id: 43, 
country: { 
name: "Iceland" 
} 
} 
}, 
{ 
{ 
id: 44, 
country: { 
name: "Cambodia" 
} 
} 
}, 
{ 
{ 
id: 45, 
country: { 
name: "North Korea" 
} 
} 
} 
] 
} 
} 

Rabl에서 할 수있는 방법이 있습니까?

답변

0

나는에 Rabl 구성 설정해야합니다 :

Rabl.configure do |config| 
    config.include_json_root = false 
    config.include_child_root = false 
end 

을 내가받은 대답은 또 다른 스택 오버플로 스레드 형성 :

Removing child root nodes in RABL

관련 문제