Reputation: 574
I am getting this error, don't know why.
NameError (uninitialized constant ShopsController::ShopService
My controller name is ShopsController I've made a service /app/services/shop_service.rb
The name of the class inside the service is ShopService
I'm using it inside a controller action the following way:
flag = ShopService.new.save_categories(@shop, params[:category])
The service code is written below
class ShopService
def initialize(shop = nil, services = nil); end
def save_categories(shop, services)
debugger
flag = true
services.drop(1).each do |service|
category = Category.new(service: service, shop_id: shop.id)
flag = false unless category.save
end
flag
end
end
Upvotes: 0
Views: 1084
Reputation: 69
Try to call the service like that: flag = ::ShopService.new.save_categories(@shop, params[:category])
on the controller, this should work
Edit:
Also, check that you are loading the services path in the config/application.rb
, on the config.autoload_paths
Upvotes: 1