在 Ruby on Rails 中识别 GET 和 POST 参数 [英] Identify GET and POST parameters in Ruby on Rails

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

问题描述

在 Ruby on Rails 中从控制器中识别和分离 GET 和 POST 参数的最简单方法是什么,这相当于 PHP 中的 $_GET 和 $_POST 变量?

What is the simplest way to identify and separate GET and POST parameters from a controller in Ruby on Rails, which will be equivalent to $_GET and $_POST variables in PHP?

推荐答案

我不知道 Rails 中有什么方便的方法来解决这个问题,但是您可以直接访问查询字符串来解析在那里设置的参数.类似于以下内容:

I don't know of any convenience methods in Rails for this, but you can access the querystring directly to parse out parameters that are set there. Something like the following:

request.query_string.split(/&/).inject({}) do |hash, setting|
  key, val = setting.split(/=/)
  hash[key.to_sym] = val
  hash
end

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

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