Ruby on Rails 3:如何分别检索POST和GET参数? [英] Ruby on Rails 3: How to retrieve POST and GET params separately?

查看:158
本文介绍了Ruby on Rails 3:如何分别检索POST和GET参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用 params 获取参数,但事实是,无论它们是通过GET还是POST发送的,它都会合并所有参数:

I know you can get parameters using params, but the thing is that it merges all parameters whether they were sent via GET or POST:

如果您通过GET发送请求,没问题,则只能在URL中压缩参数.

If you send a request via GET, no problem, the parameters can only be squeezed in the URL.

但是,如果您发送的POST请求具有类似/blabla?foo=bar&foo2=bar2的URL,是否可以区分通过URL发送的变量和通过实际的POST方法发送的变量之间的区别?

But if you send a POST request that has a URL like /blabla?foo=bar&foo2=bar2, is there a way to tell the difference between the variables sent via the URL and the variables sent through the actual POST method?

推荐答案

是的,在您的控制器中,您可以使用request.GET获取GET参数,并使用request.POST获取POST参数

Yes, in your controller you can get the GET parameters using request.GET and the POST parameters with request.POST

这篇关于Ruby on Rails 3:如何分别检索POST和GET参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆