1

我的控制器中有以下内容作为方法:

@study = Study.find(params[:id])
respond_to do |format|
  format.json { render :json => @study.to_json(:only => [:id, :first_name, :last_name, :title], :methods => [:active_users]) }
end

它正在响应 JSON 调用。active_users是一种@study转换用户数组的方法。JSON 看起来像这样:

{
    "id": 1,
    "title": "Anterior segment imaging using ultrasound biomicroscopy (UBM) and slit lamp optic coherence tomography (SL-OCT) in patients using alpha-adrenergic blockers. ",
    "active_users": [
        null,
        null,
        null,
        null
    ]
}

JSON 将作为用户的所有空值返回。我应该怎么做?

4

0 回答 0