Reputation: 7550
My product controller looks like this:
class ProductsController < InheritedResources::Base
public
def product_params(p=params)
p.require(:product).permit(:manufacturer, :part_no, :avatar)
end
end
Item
has one to one relationship with product. In Item
's controller (activeadmin) cI am doing this:
@item.product = Product.create(ProductsController.product_params(params[:item]))
And got this error:
undefined method `product_params' for ProductsController:Class
Now please help me to figure out what am I doing wrong.
Upvotes: 0
Views: 59
Reputation: 695
Your controller implement product_params
as instance method, not like static class method.
We have two ways to fix it:
products_params
as static class method.produtcs_params
to current instance.First option:
def self.product_params(p=params)
p.require(:product).permit(:manufacturer, :part_no, :avatar)
end
Second option:
@item.product = Product.create(product_params(params[:item]))
Upvotes: 1
Reputation: 6100
product_params
is an instance object method, of the class ProductsController
You are calling product_params
on class ProductsController
, and such does not exist, product_params
is not class method it is instance object method, it can only be called on instance object of ProductsController
Upvotes: 3