Lucia
Lucia

Reputation: 4767

Sinatra, retrieve only post parameters

I know I can retrieve every parameter in Sinatra using "params". However, How can I retrieve only post parameters? I need to verify that a parameter was sent by POST, otherwise it should be ignored.

Thanks.

Upvotes: 2

Views: 1068

Answers (1)

Achilles
Achilles

Reputation: 766

Accessing the request object directly gives you a simple way of accessing post data, much like the php $_POST variable:

post '/' do
  request.POST.inspect # instead of params.inspect
end

More info on the Rack request object here: http://rack.rubyforge.org/doc/classes/Rack/Request.html#M000274

Upvotes: 5

Related Questions