当我尝试这段代码时,它在 201 状态码的情况下工作......
resource_m = RestClient::Resource.new Rails.application.config.sta+"/mov"
resource_m = resource_m.post @hash.to_json, :content_type => :json, :accept =>:json
puts "code...#{resource_m.code}"
case resource_m.code
when 201
respond_to do |format|
@noticec = {:name =>"Successfully",:code => "201"}
format.json { render :json => @noticec }
end
when 409
respond_to do |format|
@noticec = {:name =>"already exists",:code => "409" }
format.json { render :json => @noticec }
end
when 401
respond_to do |format|
@noticec = {:name =>"Error",:code => "401" }
format.json { render :json => @noticec }
end
else
respond_to do |format|
@noticec = {:name =>"Something went wrong" }
format.json { render :json => @noticec }
end
end
但是如果来自服务器的响应代码是 409,rails 给出一个错误 Completed 500 Internal Server Error in 1370ms ActionView::MissingTemplate (Missing template)。 但是当我在 REST-CLIENT 中尝试这个时,我可以看到状态码是 409 冲突。. 我无法在控制器中获取该响应代码。