Chloe
Chloe

Reputation: 26264

How do I include stylesheets from a gem into the main app?

How do I access the styles in a gem from my main application? I created a 'refinerycms-carts' gem and added this file:

refinerycms-carts/app/assets/stylesheets/application.sass

However, when I reload the page and search for the class in application.css in the browser (F12), it does not find it.

I tried adding this line to main app's app/assets/stylesheets/application.css.scss

@import 'refinerycms-carts';

But it gave an error "File to import not found or unreadable: refinerycms-carts."

I also tried naming the file carts.sass but still could not find the class I was referencing.

Yes I'm in development mode. Yes, other changes like controller or models or view are updated and reloaded.

Main app Gemfile: gem 'refinerycms-carts', :path => '../refinerycms-carts'

This is in my refinerycms-carts.gemspec: s.files = Dir["{app,config,db,lib}/**/*"] + ["readme.md"]

This is in my gem Gemfile: gem 'sass-rails'

The gem acts as an Engine.

Rails 3.2.14.

Upvotes: 1

Views: 551

Answers (1)

Chloe
Chloe

Reputation: 26264

I had to add this in one of my Gem's views:

-content_for :stylesheets, stylesheet_link_tag('refinery/carts')

I also renamed the file to app/assets/stylesheets/refinery/carts.sass. There was already a yield :stylesheets in the app's layout.

Upvotes: 1

Related Questions