jeudi 8 décembre 2016

return { } if user has no data

I am new to json and my json looks like

@daily_work
   json.work @daily_work do |work|`
    json.minutes                    work.total_minutes
    json.calories                   work.calories

   end
 json.regular do
   unless @regular.blank?
    json.id                         @regular.IncentiveID
    json.unit                       @regular.IncentiveUnit
    json.schedule do
      json.points                  @regular.ExercisePoints
      json.date                    @date
    end
   end
 end`

This returns users exercise details. I want to show json in following format if its a new user and user doesnt have work, regular or schedule deatails

work []
regular {}
schedule {}

how can i achieve that?

Aucun commentaire:

Enregistrer un commentaire