我試圖創建一個gem來放置所有常用樣式表。我無法弄清楚如何在Rails應用程序中導入樣式表。這是我到目前爲止已經進行(以下this guide):爲共享樣式表創建gem並在Rails應用程序中使用它
我跑
bundle gem apple_core
。我修改apple_core.rb包含像這樣一個軌道引擎類:
require "apple_core/version" module AppleCore class Engine < Rails::Engine end end
我創建使用
mkdir -p lib/apple_core/app/assets/stylesheets/apple_core
的apple_core樣式表目錄。我創建了apple_core樣式表目錄中的索引文件,並添加以下代碼行:
/* *= require_self *= require_tree . */
我在同一個目錄做了test.css.scss文件,並補充說:
a { color: red; }
我爲這個gem創建了一個GitHub倉庫並將其推送。
在我的Rails應用程序中,我將gem添加到資產組中的Gemfile中。我想跑
bundle install
。
我想,包括我在使用@import "apple_core";
我的文件中的一個瑰寶,但是當我試圖加載的頁面,我收到一個couldn't find file 'apple_core'
錯誤。我在這裏錯過了什麼?
在'vendor/apple_core/app/assets/stylesheets/apple_core'中移動'lib/apple_core/app/assets/stylesheets/apple_core' – apneadiving
你說'@import「apple_core」'是什麼類型的文件? – moritz
@mosch這是一個scss文件。 – LandonSchropp