Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails parameters from GET/POST

I'm fairly new to Rails and am writing a login form. I have used form_tag to pass through the user's submission to the account controller. Now, I don't want the user to be able to enter their login details through a GET request, so how can I check that a certain param is either a GET or POST parameter?

Thanks in advance

like image 338
alex Avatar asked Oct 26 '10 12:10

alex


People also ask

What is params [: id in Rails?

params[:id] is meant to be the string that uniquely identifies a (RESTful) resource within your Rails application. It is found in the URL after the resource's name.

What is params in ROR?

Specifically, params refers to the parameters being passed to the controller via a GET or POST request. In a GET request, params get passed to the controller from the URL in the user's browser.

What does Before_action do in Rails?

When writing controllers in Ruby on rails, using before_action (used to be called before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It's what you want to use to "prepare" the data necessary before the action executes.


2 Answers

In Rails you don't have specific POST or GET parameters. You do have a POST or GET request. You can check it like this in your controller:

request.post?

or you can check for other HTTP verbs: GET, PUT and DELETE:

request.get?
request.put?
request.delete?

For more info, check this piece of the documentation: http://railsapi.com/doc/rails-v2.3.8/classes/ActionController/Request.html

like image 185
Ariejan Avatar answered Oct 03 '22 16:10

Ariejan


If what you need is to know the HTTP verb you can ask directly to request:

request.request_method 
like image 38
hcarreras Avatar answered Oct 03 '22 15:10

hcarreras