Rails: How to get all parameters from url?

Ruby on-RailsRuby on-Rails-3

Ruby on-Rails Problem Overview


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?

  $_GET or $_POST

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmlzboyView Question on Stackoverflow
Solution 1 - Ruby on-RailsalnoView Answer on Stackoverflow