What are Params in Ruby

Q: What are params in Ruby?

A: params in Ruby are equivalent of $_REQUEST array in PHP. They can come from:

  • query string of GET request,
  • input from POST request,
  • or the path of the URL.

If user requested

http://localhost:4567/bill

then

params[:name]

are “bill”

Example:

require 'sinatra'
get '/:name' do
name = params[:name]
"Hi there #{name}!"
end

will return value depending on user’s input. If you enter

http://localhost:4567/BILL

You will get

Hi there BILL!

If you request

http://localhost:4567/what/time/is/it/in/2/hours

params id was set to “2” and so on.

Sources: http://stackoverflow.com/questions/6885990/rails-params-explained