ROR - 从HTTP响应位置提取ID

时间:2014-03-12 16:06:02

标签: ruby-on-rails http rest location response-headers

我有一个对Java服务的REST调用,它对路径进行POST

localhost:8080/api/xyz 

并返回响应。响应当然有response.header ['location'],其ID位置正确

'xyz/{id}'    

对于我在方法中的进一步步骤,我只需要从'location'中提取'id'部分。现在这就是我在做的事情,

(response.header['location'].split('/'))[1]

有没有更好的解决方法?

1 个答案:

答案 0 :(得分:0)

rails提供的解决方案之一:

# routes.rb
get '/api/:id'

# view or controller
params[:id]