how to include stylesheet in root folder of rails 3
Due to some heroku problems with rails 3 and compass framework, we followed this guide:
http://lds.li/post/673242899/compass-with-rails-3-on-heroku
and moved our stylesheets to app_name/tmp/stylesheets.
I tried using
stylesheet_link_tag "#{Rails.root}/tmp/stylesheets/main.css"
but that doesnt work as it looks for the css file in
http://localhost:3000/app_name/tmp/stylesheets/main.css
I know this is a simple开发者_如何学Go fix and I'm overlooking something simple but hopefully someone can answer this with one look. Thanks in advance!
I would like to point out that we have this in our stylesheets.rb
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets/compiled'],
:root => "#{Rails.root}/tmp")
WHen I try "compass watch" it still compiles to "tmp/stylesheets/main.css" instead of stylesheets/compiled.
I personally take a different approach to solving this problem:
Stick the following code in your compass initializer:
Sass::Plugin.options[:never_update] = true
This prevents sass from trying to write to your filesystem when the server is hit.
Just make sure that you are running compass watch in development mode and commit the compiled stylesheets to yout git repo
This saves so much time - if you don't like this approach, try hassle or one of the recent forks
Change your config/compass.rb
to set css_dir = "tmp/stylesheets/compiled"
Based on what you have in your configuration, you should be using this for your template:
stylesheet_link_tag "compiled/main.css"
(Which renders <link rel="/stylesheets/compiled/main.css" ...
)
(The tmp
dir is outside of public
; it shouldn't appear in the URLs because the middleware is taking care of remapping it.)
精彩评论