여기에 다른 JSON 렌더링 문제를 연구했지만 배열로 끝내려하지 않는 것을 발견하지 못했습니다. 해시로 렌더링하는 것에 대한 많은 게시물을 발견했지만 도움이되지 않았습니다.하나의 DB 열에서 문자열의 JSON 배열을 렌더링합니다.
최근 시도는 다음과 같습니다
def create
params[:_json].each do |ip|
IpAddress.create(ip: ip)
end
ips = IpAddress.pluck(:ip)
ips.each do |ips|
ips.to_s
end
render json: ips
end
뿐만 아니라
def create
params[:_json].each do |ip|
IpAddress.create(ip: ip)
end
render json: IpAddress.all, methods: [:ip]
end
이러한 시도는 모두 데이터베이스 행의 전체 배열을 반환합니다.
도움을 주시면 감사하겠습니다. 감사!
'ips = IpAddress.pluck (: ip)'그리고'render json : {ips : ips}'? – MrYoshiji