Rails: How to get all parameters from url?

Usually we use:

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

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

  $_GET or $_POST 
+42
ruby-on-rails ruby-on-rails-3
Dec 04 '10 at 9:26 a.m.
source share
1 answer

You can 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 that params includes category options:

  • Path parameters (related in routes)
  • Request Parameters (GET)
  • Request Parameters (POST)

If you want to access the parameters of a certain category, you can use:

 request.path_parameters request.query_parameters # or request.GET request.request_parameters # or request.POST 

All methods return HashWithIndifferentAccess , so you can access them using a string or a character key.

+107
Dec 04 '10 at 9:30
source share



All Articles