2014-07-15 3 views
0

이전에 답을 찾지 못했기 때문에 질문을 반복하고 있습니다!json을 평평하게 만드는 방법은 무엇입니까?

나는 Rabl을 시작으로 부모 속성을 포함하지만 어린이와 동일한 수준으로 포함하려고합니다. 이것은 내가 지금까지 무엇을 가지고

..

class Usertag < ActiveRecord::Base 
    belongs_to :tag 
    attr_accessible :user_id, :tag_id 
end 

내 index.json.rabl

object @usertag 
attributes :id 
child :tag do 
    attributes :name 
end 

[{"usertag":{"id":1,"tag":{"name":"Dolor et non."}}}, 

가 어떻게이의 자식 노드를 평평 않는 생산 생성하는 템플릿

[{"usertag":{"id":1,"name":"Dolor et non." 

감사!

답변

1

당신은 index.json.rabl 사용자 정의 노드를 사용하여 수정할 수 있습니다

object @usertag 
attributes :id 
node :name do |ut| 
    ut.tag.name 
end 

그것이 도움이되기를 바랍니다.

관련 문제