레일스로 API를 구축 중입니다. 내가 API를 만드는 데 사용하는 보석은 포도와 Rabl입니다. 나는 많은 일을했지만 지금은 API에서 모든 json 응답 앞에 status
플래그를 추가해야합니다. 내가 어떻게 할 수 있니?json 출력에 맞춤 키 - 값 쌍 추가하기 포도 및 Rabl
나는이 .rabl
파일을 가지고 있습니다.
object @current_parent
attributes :first_name => :name
attributes :cell_phone => :mobile
attributes :email
attributes :address
node :day_care do |m|
{
:name => current_day_care.name,
:address => current_day_care.address,
:phone => current_day_care.office_phone,
:website => current_day_care.website,
:logo => current_day_care.logo.url,
:no_of_child => current_parent.relatives.count
}
end
child :relatives, :object_root => false do |m|
child :child, :object_root => false do |n|
attributes :id
attributes :first_name => :name
attributes :gender
attributes :student_stage => :classroom
end
end
이것은 다음과 같은 출력
{
"parent": {
"name": "Devan",
"mobile": "1234567891",
"email": "[email protected]",
"address": "762 Beahan Expressway",
"day_care": {
"name": "Brisa Erdman",
"address": "859 Hermann Summit",
"phone": "915.758.4580",
"website": "fisher.info",
"logo": "/uploads/day_care/logo/1/http%3A/example.com/ally",
"no_of_child": 2
},
"relatives": [
{
"child": {
"id": 1,
"name": "Lucious",
"gender": "t",
"classroom": "PreKindergarten"
}
},
{
"child": {
"id": 2,
"name": "Lilly",
"gender": "t",
"classroom": "Toddlers"
}
}
]
}
}
하게하지만 parent
아래
{
"status": "Success"
"parent": {
"name": "Devan",
"mobile": "1234567891",
"email": "[email protected]",
처럼 열립니다하지만 난 방법을 알아낼 질수 전에 나는 처음에 status
플래그를 갖고 싶어 이것이 rabl을 사용하여 일어나는 것. 제발 이걸 안내 해줘. 가능한 경우 대체 솔루션을 제공하십시오.
이것은 작동합니다. 고마워요. 나는 또 다른 방법을 찾아 냈다. 내 대답도 올릴거야. – mgs