我有一個名爲Blog的Rails安裝引擎。Rails引擎沒有在資源預編譯中加載
在模塊內部,我有一個名爲root_path的方法。該模塊加載引擎的根路徑。
module Blog
def self.root_path
Engine.routes.url_helpers.root_path
end
end
在Rails引擎的javascript資源中,我使用erb語法加載引擎的根url。就像下面一行:
url = <%= Blog.root_path %>
當我運行,rake assets:precompile
,我的應用程序裏面,我得到一個錯誤,該模塊中不包含這種方法。就像在預編譯資源之前不加載引擎庫一樣。
的錯誤是:
undefined method `root_path' for #< Module:0xc185e14>
是的,Rails引擎的實現很糟糕。 ;) – Macario 2012-10-10 18:34:52
同樣,資產管道通常會造成比解決問題更多的麻煩。 – Macario 2012-10-10 18:38:59