【发布时间】:2013-06-26 14:46:55
【问题描述】:
当我尝试这段代码时,它在 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 1370 毫秒内的服务器错误 ActionView::MissingTemplate(缺少模板)。 但是当我在 REST-CLIENT 中尝试这个时,我可以看到状态码是 409 冲突。。我无法在控制器中获取该响应代码。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2