簡體   English   中英

在服務類中使用rails引擎路徑助手

[英]Using rails engine path helpers in a service class

我在我的rails應用程序中安裝了一個引擎。 在控制器中,我可以通過在路徑前添加引擎名稱來訪問引擎路徑助手,例如myengine.articles_path 我想在服務類中訪問這些幫助程序。 通常我會包括url_helpers即

class SomeService
  include Rails.application.routes.url_helpers

end

這允許我訪問我的主應用程序中的幫助程序,例如root_path ,但如果我嘗試myengine.articles_path我得到

undefined local variable or method `myengine'

如何訪問服務類或類似模塊中的引擎路徑助手?

它必須被列入class << self

class SomeService
  class << self
   include Rails.application.routes.url_helpers
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM