2

RailsでAPIを構築しています。API の構築に使用する gem は、Grape と Rabl です。私は多くの作業を行いましたがstatus、API からのすべての json 応答の前にフラグを追加する必要があります。どうすればこれを行うことができますか?

私はこの.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": "testparent1@mail.com",
    "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"
            }
        }
    ]
}
}

しかし、以下のように開くstatus前に、最初にフラグを立てたいparent

{
"status": "Success"
"parent": {
    "name": "Devan",
    "mobile": "1234567891",
    "email": "testparent1@mail.com",

しかし、rabl を使用してこれを実現する方法がわかりません。これを案内してください。不可能な場合は、代替ソリューションを提供してください。

4

2 に答える 2