Reputation: 171351
I use params
in my controller like this:
class ProductsController < ApplicationController
def create
@product = Product.new(params[:aircon])
...
end
end
Is params
an attribute of ApplicationController
? I guess not, because it does not have the @
prefix. So, what actually params
is ? Can I use it in any custom method in ProductsController
?
Upvotes: 11
Views: 3191
Reputation: 35505
The parameters are actually being parsed in middleware called ActionDispatch::ParamsParser. The params
function in ActionController::Metal
is a wrapper for this.
Upvotes: 7
Reputation: 1425
It's defined in ActionController::Metal. ApplicationController inherits from ActionController::Base, which inheirts from ActionController::Metal. If you look at the Rails API at http://api.rubyonrails.org/, you will find params
is just a function that returns the paramaters of the request
object.
Upvotes: 11