2
似乎无法从我创建的服务中调用此辅助方法。他们是这样的:在服务中调用辅助方法
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
helper_method :activate_session_with_id
def activate_session_with_id(domain, token)
#do some stuff
end
end
我的服务是这样的:
# app/services/fulfillment_order.rb
class FulfillmentOrder
def create_order_user_fulfilled
shop = Shop.find_by(shopify_domain: @domain)
shop_token = shop.shopify_token
ApplicationController.helpers.activate_shopify_session_with_id(@domain, shop_token)
end
end
当我这样做,我得到这个错误
NoMethodError (undefined method activate_shopify_session_with_id
我也试着拨打helper方法直线上升,如下所示:
activate_shopify_session_with_id(@domain, shop_token)
N运气无论哪种方式。我在哪里误入歧途?
好,感谢suggestion.Ahh,所以如果我创建了这个方法的模块,我只想包括服务的模块,并调用方法根据需要?是? – ToddT
@ToddT是的,你会包括它在任何类,使用这种方法:) –