问题描述
我目前正在Heroku上使用Compass,使用Heroku知识推荐的基础。 Heroku有一个只读文件系统,因此编译的样式表需要存储在/ tmp中。这在Heroku上可以很好地工作。然而,在本地,Rails希望在/ public / stylesheets中找到样式表(当通过 = stylesheet_link_tag'screen.css',:media =>'screen,projection'
调用时) 。
为了解决这个问题,我使用 ln -s tmp / stylesheets / screen.css在/ public / stylesheets中创建了符号链接public / stylesheets / screen.css
,这似乎工作。
有没有办法解决这个问题,而不使用符号链接,也许在Rails中改变一些配置?
这是我的config / initializers / compass.rb:
require'compass'
require'compass / app_integration / rails'
Compass :: AppIntegration :: Rails.initialize!
#Heroku需要:
需要'fileutils'
FileUtils.mkdir_p(Rails.root.join(tmp,stylesheets))
Compass :: AppIntegration :: Rails.initialize!
Rails.configuration.middleware.delete('Sass :: Plugin :: Rack')
Rails.configuration.middleware.insert_before('Rack :: Sendfile','Sass :: Plugin ::'Rack')
Rails.configuration.middleware.insert_before('Rack :: Sendfile','Rack :: Static',
:urls => ['/ stylesheets'] ,
:root =>#{Rails.root} / tmp)
这里是我的配置/ compass.rb:
project_type =:rails
project_path = Compass :: AppIntegration :: Rails.root
#在部署时将其设置为您项目的根目录:
http_path =/
#Heroku必需(原始注释:
css_dir ='tmp / stylesheets'
#css_dir =public / stylesheets / compiled
sass_dir ='app / views / stylesheets'
environment = Compass :: AppIntegration :: Rails.env
任何帮助将不胜感激。
我是实际上我们正准备用我们的Heroku托管的Rails应用程序来设置Compass,所以欢呼我给了我一个解决方案的借口。 :)
答案很简单:
修改'config / compass.rb':
project_type =:rails
project_path = Compass :: AppIntegration :: Rails.root
http_path = /
environment = Compass :: AppIntegration :: Rails.env
if environment =='production'
css_dir =tmp / stylesheets
sass_dir = app / views / stylesheets
else
css_dir =public / stylesheets
sass_dir =app / stylesheets
end
然后修改'config / initializers / compass.rb':
require'compass'
require'compass / app_integration / rails'
Compass :: AppIntegration :: Rails.initialize!
需要'fileutils'
FileUtils.mkdir_p(Rails.root.join(tmp,stylesheets))
environment = Compass :: AppIntegration: :Rails.env
if environment =='production'
Compass :: AppIntegration :: Rails.initialize!
Rails.configuration.middleware.delete('Sass :: Plugin :: Rack')
Rails.configuration.middleware.insert_before('Rack :: Sendfile','Sass :: Plugin ::'Rack')
Rails.configuration.middleware.insert_before('Rack :: Sendfile','Rack :: Static',
:urls => ['/ stylesheets'] ,
:root =>#{Rails.root} / tmp)
结束
...和瞧,你很好。
I'm currently using Compass with Heroku using this configuration recommended on the Heroku knowledge base. Heroku has a read-only file system, and so the compiled stylesheets need to be stored in /tmp. This works fine remotely on Heroku; locally, however, Rails expects to find stylesheets in /public/stylesheets (when called through = stylesheet_link_tag 'screen.css', :media => 'screen, projection'
).
In order to solve the problem, I have created symbolic links in /public/stylesheets using ln -s tmp/stylesheets/screen.css public/stylesheets/screen.css
and that seems to work.
Is there a way to solve this problem without using symbolic links, perhaps by changing some configuration in Rails? I've poked around without much success.
Here is my config/initializers/compass.rb:
require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!
# Required for Heroku:
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
Compass::AppIntegration::Rails.initialize!
Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets'],
:root => "#{Rails.root}/tmp")
And here is my config/compass.rb:
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
# Set this to the root of your project when deployed:
http_path = "/"
# Necessary for Heroku (original commented out:
css_dir = 'tmp/stylesheets'
#css_dir = "public/stylesheets/compiled"
sass_dir = 'app/views/stylesheets'
environment = Compass::AppIntegration::Rails.env
Any help would be greatly appreciated.
I was actually just about to set up Compass with our Rails application, which is hosted on Heroku, so cheers for giving me an excuse to work through this. :)
The answer is simple:
Modify 'config/compass.rb':
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
http_path = "/"
environment = Compass::AppIntegration::Rails.env
if environment == 'production'
css_dir = "tmp/stylesheets"
sass_dir = "app/views/stylesheets"
else
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
end
Then modify 'config/initializers/compass.rb':
require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
environment = Compass::AppIntegration::Rails.env
if environment == 'production'
Compass::AppIntegration::Rails.initialize!
Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets'],
:root => "#{Rails.root}/tmp")
end
... and voila, you're good.
这篇关于在Heroku上使用Compass:/ tmp用于远程和本地样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!