NoMethodError in WebController#web_subcategory

undefined method `id' for nil:NilClass

Extracted source (around line #304):
302
303
304
305
306
307
          
else
brand = Brand.where(:name => params[:brand]).first
@products = Product.includes(:brand, :collection).where("category_id in (?) or second_category in (?)", @cats, @cats).where(:brand_id => brand.id).where(:hidden => 0).order("collections.position ASC, brands.position ASC, products.price ASC")
end
#Fin categorías superiores

Rails.root: /var/www/vhosts/shopmultimarca.es/shopmultimarca

Application Trace | Framework Trace | Full Trace
app/controllers/web_controller.rb:304:in `web_subcategory'

Request

Parameters:

{"brand"=>"LEVI%C2%B4S",
 "id"=>"39-nina"}

Response

Headers:

None