开发者

Rails: How to get all parameters from url?

开发者 https://www.devze.com 2023-01-28 02:55 出处:网络
Usually, we us开发者_如何学Ce like: params[:a] #to get a specific parameter\'s value But how to get all the parameters the way we do in PHP?

Usually, we us开发者_如何学Ce like:

 params[:a] #to get a specific parameter's value

But how to get all the parameters the way we do in PHP?

  $_GET or $_POST


You may simply use params as a Hash of all passed parameters (both GET and POST).

For example:

params.each do |key,value|
  Rails.logger.warn "Param #{key}: #{value}"
end

Update: Note, what params include parameters of categories:

  • Path parameters (bound in routes)
  • Query parameters (GET)
  • Request parameters (POST)

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号