我在我的控制器中使用params如下所示:
- class ProductsController < ApplicationController
- def create
- @product = Product.new(params[:aircon])
- ...
- end
- end
params是ApplicationController的属性吗?我猜不是,因为它没有@前缀.那么,什么是params呢?可以在ProductsController中的任何自定义方法中使用它吗?
解决方法
它在ActionController :: Metal中定义. ApplicationController继承自ActionController :: Base,它来自ActionController :: Metal.如果您在
http://api.rubyonrails.org/处查看Rails API,您将发现params只是返回请求对象参数的函数.