0
在我们的客户模型(导轨3.2.12),一种方法是find_customers
定义如下:是否可以在索引操作(rails 3.2.12)中创建params [:customer]?
def find_customers
customers = Customerx::Customer.scoped
customers = customers.where("sales_id = ?", sales_id_s) if sales_id_s.present?
customers
end
sales_id_s
的通过图形式经由params[:customer][:sales_id_s]
传递英寸我们希望使用相同的find_customers
方法来回报客户控制器索引操作中的客户。的代码是:
def index
if has_index_individual_right?('customerx_customers')
params[:customer][:sales_id_s] = session[:user_id]
customer = Customerx::Customer.new(params[:customer])
@customers = customer.find_customers
else
......
end
......
end
然而代码params[:customer][:sales_id_s] = session[:user_id]
导致错误:undefined method
[] =”的零:NilClass`。在调试中,params [:customer]返回nil。
有没有办法在索引操作中创建params[:customer]
对象,因此我们可以调用模型方法find_customers
?
感谢您的帮助。