I know this question asked many times. But I want to get out of this. Below is my code.
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
render
call at the start of your coderequest.format.json? ? "#{render :json =>
and one at the endrender :json => patients
. You need to structure your code so that it doesn't execute both, either with areturn
or a condition. Also, not sure why your code at the top is within#{}
strings. – mikej