Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the rails 'params' without the defaults?

Is there a neat way in rails to get a hash of the params without the default ones of 'action' and 'controller'? Essentially without any param that wasn't added by me.

I've settled for:

parm = params.clone parm.delete('action') parm.delete('controller'); 

But wondering if there is a neater way to do this?

like image 638
William Denniss Avatar asked Sep 19 '11 07:09

William Denniss


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 are strong parameters in Rails?

Strong Parameters, aka Strong Params, are used in many Rails applications to increase the security of data sent through forms. Strong Params allow developers to specify in the controller which parameters are accepted and used.

What is params require in rails?

The require method ensures that a specific parameter is present, and if it's not provided, the require method throws an error. It returns an instance of ActionController::Parameters for the key passed into require . The permit method returns a copy of the parameters object, returning only the permitted keys and values.

How does params get built in rails?

params comes from ActionController::Base, which is accessed by your application via ApplicationController. Specifically, params refers to the parameters being passed to the controller via a GET or POST request.


1 Answers

You could use except:

params.except(:action, :controller) 

http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Except.html

like image 67
Volker Pacher Avatar answered Oct 06 '22 18:10

Volker Pacher