我知道这个问题问了很多次。但我想摆脱这一切。下面是我的代码。
request.format.json? ?
"#{render :json => {:success => false, :message => 'Exception, provider code not found'}}" :
"#{raise 'Exception, provider code not found'}" if params[:provider_code].nil? || params[:provider_code].empty? || params[:provider_code].blank?
# Setting params for patient details.
conditions = {}
conditions['providers.provider_code'] = params[:provider_code] unless params[:provider_code].blank?
# Using scope to fetch record based on applied conditions.
patients = Patient.with_messages_provider.where(conditions)
# Response for patient details.
patients = Patient.patients_for_provider(patients)
render :json => patients