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?

  $_GET or $_POST

Answers


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.


Need Your Help

How to pass event to named function on.('click')?

jquery

I have the following trigger in jquery:

Python and Incapsula

python

I have been scraping a website and it works, but suddenly it does not work anymore which I found out incapsula protection in their website. I read the new TOS and it mentions that as long as it is ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.