[英]Rails: How to get all parameters from url?
Usually, we use like: 通常,我们使用如下:
params[:a] #to get a specific parameter's value
But how to get all the parameters the way we do in PHP? 但是如何以我们在PHP中的方式获取所有参数?
$_GET or $_POST
You may simply use params
as a Hash of all passed parameters (both GET and POST). 您可以简单地使用
params
作为所有传递参数的哈希(GET和POST)。
For example: 例如:
params.each do |key,value|
Rails.logger.warn "Param #{key}: #{value}"
end
Update: Note, what params
include parameters of categories: 更新:注意,什么
params
包括类别的参数:
If you want to access parameters of certain category only you may use: 如果您只想访问某些类别的参数,您可以使用:
request.path_parameters
request.query_parameters # or
request.GET
request.request_parameters # or
request.POST
All methods return HashWithIndifferentAccess , so you may access them by string or symbol key. 所有方法都返回HashWithIndifferentAccess ,因此您可以通过字符串或符号键访问它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.