It's quite clear that the category with provided name doesn't exist (so Category.find_by_name
method returns nil
).
You probably don't set @params
instance variable properly.
About your second error, the last line in your code should be:
@subcat = Category.where(id: @sub_ids)
Or, to make it simpler, you could use existing library to handle this kind of logic, like acts_as_tree.