Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Where "params" is defined?

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 ?

like image 501
Misha Moroshko Avatar asked Dec 15 '10 23:12

Misha Moroshko


2 Answers

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.

like image 50
icecream Avatar answered Nov 03 '22 09:11

icecream


The parameters are actually being parsed in middleware called ActionDispatch::ParamsParser. The params function in ActionController::Metal is a wrapper for this.

like image 27
Adam Lassek Avatar answered Nov 03 '22 09:11

Adam Lassek