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 ?
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.
The parameters are actually being parsed in middleware called ActionDispatch::ParamsParser. The params function in ActionController::Metal is a wrapper for this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With