I am working on a ruby API's.This API fetching db value and converted into a JSON format.
Below code used to fetch data from db and converted into JSON format
def get_data
response= data.select(:xx, :xxx, :xxx, :xxx ).where(:id => xxx1,:xx1 => xx1)
if response.empty?
respond_to do |format|
msg = {:message => "No records found"}
format.json { render :json => msg }
end
else
respond_to do |format|
format.json { render json: response.to_json }
end
end
end
Now am getting the response like below
How can i remove the slash from the response? Thanks in advance.
Note: I was tested this API's from POSTMAN
Executed following solutions but the result was same
use as_json
instead of to_json
removed .to_json
I don't think you can use the variable response
in a controller action.
It is already used by Rails: https://guides.rubyonrails.org/action_controller_overview.html#the-response-object
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.