당신은 당신의 레일 컨트롤러를 설정하면 다음과 같음 :
respond_to : JSON
JSON으로 내가 만든
class XYZController < ApplicationController
respond_to :html, :json
responders :jsons
def create
@xyz = Xyz.new(params[:xyz])
@xyz.save
respond_with @xyz, :location=>@xyz.id.nil? ? "" : edit_xyz_url(@xyz)
end
end
(당신이 respond_with (객체)를 사용합니다) 당신은 당신의 오류를 받게됩니다 내 백본을 더 잘 다룰 수있는 json 응답자 :
module Responders
module JsonResponder
def to_json
raise error unless resourceful?
if get?
display resource
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
elsif post?
display resource, :status => :created, :location => api_location
elsif put?
display resource, :status=>:ok, :location => api_location
elsif has_empty_resource_definition?
display empty_resource, :status => :ok
else
head :ok
end
end
end
end
@ Julien 어떻게하면이 응답을 사용자의 예제에서 처리 할 수 있습니까? 백본에서 .js? 나는보고 싶어한다. –
은 반응기 보석을 사용합니까? –
예 답변자 보석을 사용합니다 – Julien