生产模式下是否有适用于 Rails 3.1 以及 Scss、Haml、Compass 和 HTML-Boilerplate 的有效 Gemfile?

发布于 2024-12-03 09:18:43 字数 1810 浏览 2 评论 0原文

我有一个成功的 Rails 3.0.x 项目,在 Gemfile 中包含以下 Gems 子集:

gem "compass"
gem "haml"
gem "haml-rails"
gem "html5-boilerplate"

今天我尝试升级到 Rails 3.1 并保留所有功能,但在这样做时遇到了很多问题。我还没有找到在生产模式下适合我的配置,所以我现在正在开发模式下工作。

我在这里遵循了以下建议:

所以我的问题是:是否有一个有效的 Gemfile 允许一起使用 Haml、Sass、Compass、Html5-Boilerplate,当然还有 Rails 3.1?

新的 Gemfile 在开发模式下工作,但不在生产模式下工作:

gem "haml-rails"
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha.0'
  gem "html5-boilerplate"
end
gem 'jquery-rails'

我尝试创建一个新的 Rails 3.1 应用程序,并在其中添加了图像资源。一切都工作正常,因此开发模式和生产模式没有区别。在我迁移的应用程序中,我现在处于以下状态:

  • 在开发模式下运行良好。
  • 禁用一些 html5-boilerplate 的东西来解决生产中的问题。
  • 尚未找到生产模式下的预编译映像。

I have a successful Rails 3.0.x project with the following subset of Gems in the Gemfile:

gem "compass"
gem "haml"
gem "haml-rails"
gem "html5-boilerplate"

I tried today to upgrade to Rails 3.1 and keep all functionality, and had numerous problems in doing so. I did not yet find a configuration that did work for me in production mode, so I am working now with developing mode.

I followed the following advices here:

  • "Upgrading to Rails 3.1" from Railscast: very good as usual, and told me how to change production.rb, development.rb and application.rb to update the configuration for the asset pipeline. But did not touch compass, sass, and html5-boilerplate.
  • "Setup html-boilerplate with Rails 3.1" That contained the best fit for me, but does not work, because the method ie_html is not available in production mode. The change in the Gemfile is noted down
  • "Unable to get Rails 3.1, Compass, Sass, Blueprint working on Heroku Cedar" This did not work for me at all, I had problems to the the assets compiled then. There the try was to have everything global, because there is a dependency between Compass and Html-Boilerplate, and Html-Boilerplate has to be global due to the method ie_html.
  • Every try to use only some the Gems in the group :assets block was not successful. Most of the time, the dependency between e.g. compass and sass, or compass and html5-boilerplate could not be fulfilled.

So my question is: Is there a working Gemfile which allows to use Haml, Sass, Compass, Html5-Boilerplate and of course Rails 3.1 together?

New Gemfile working in development mode, but not in production mode:

gem "haml-rails"
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha.0'
  gem "html5-boilerplate"
end
gem 'jquery-rails'

I have tried to create a fresh Rails 3.1 application, and added there an image resource. There everything is working fine, so no difference between development mode and production mode. In my migrated application, I have now the following state:

  • Works well in development mode.
  • Disable some of the html5-boilerplate things to work around the problems in production.
  • Does not find yet the precompiled images in production mode.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疯了 2024-12-10 09:18:43

我让它在 Heroku Cedar 上工作。

gem "rails", "~> 3.1.0"
gem 'sass-rails', "~> 3.1.0"

group :assets do
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha.0'
  gem 'html5-boilerplate'
end

但在 git push heroku 之前,首先在本地预编译:

RAILS_ENV=production bundle exec rake assets:precompile

然后将所有公共/资产添加到您的 git 存储库并提交。然后:

git push heroku master

Heroku 将检测 public/assets/manifest.yml 文件并仅使用这些文件。

这对我有用,所以应该有用!干杯

I have it working on Heroku Cedar.

gem "rails", "~> 3.1.0"
gem 'sass-rails', "~> 3.1.0"

group :assets do
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'compass', '~> 0.12.alpha.0'
  gem 'html5-boilerplate'
end

But before git push heroku first precompile locally with:

RAILS_ENV=production bundle exec rake assets:precompile

then add all public/assets to your git repo and commit. Then:

git push heroku master

Heroku will detect the public/assets/manifest.yml file and just use these files.

This works for me so should work! Cheers

毅然前行 2024-12-10 09:18:43

只是为了包含一些其他人可能会有所帮助的信息,这里是我目前有效的情况(或多或少):

  • 我已经定义了 Gemfile 就像问题中定义的那样。
  • 因此,我必须确保 html5-boilerplate 在生产模式中使用。我已经注释掉了我不需要的部分 html 代码。我(大部分)使用 html5-boilerplate 模板,并且该应用程序仅在我的本地 PC 上,因此使用 Google 的 jquery 等获得的性能与我无关。
  • 已解决:生产模式下图像的问题(请参阅我当前无法解决的一个问题 使用 Rails 3.1 时如何在 Sass 中使用参考图像?Rails 3.1.0 - asset:使用 asset_url() SASS 函数时预编译失败 尚未解决在 Rails 3.1.0)) 中,由于 Rails 3.0.x 应用程序迁移到 Rails 3.1.0,导致出现配置问题。我通过复制新创建的应用程序的工作配置(主要是包含错误条目的 production.rb )解决了这个问题。

我不会在这里投入更多时间,等待 Rails 3.1.1 和 html5-boilerplate 的更新。

Just to include some of the information that may others help, here my current situation that works (more or less):

  • I have defined the Gemfile like defined in the question.
  • Therefore I had to ensure that the html5-boilerplate is not used in production mode. I have commented out parts of the html code that I do not need. I use the html5-boilerplate templates (mostly), and the application is on my local PC only, so the performance gain by using e.g. jquery from Google is not so relevant for me.
  • Solved: The problems with the images in production mode (see one problem I could not solve currently at How do I use reference images in Sass when using Rails 3.1?, and the Rails 3.1.0 - asset:precompile fails when using asset_url() SASS function which is not solved in Rails 3.1.0)) where configuration problems due to the migration of Rails 3.0.x app to Rails 3.1.0. I solved it by copying a working configuration of a new created app (mostly production.rb which contained the wrong entry).

I will not invest more time here, and wait for updates for Rails 3.1.1 and html5-boilerplate.

我的痛♀有谁懂 2024-12-10 09:18:43

首先,我很抱歉添加另一个答案,但我认为历史对其他人有帮助。

我再次尝试(感谢@theanym的评论)使用rails 3.1.1、html5-boilerplate、compass、sass和haml创建一个新应用程序,并且我找到了一个适用于开发和生产模式的工作解决方案。

这些是我采取的步骤:

  1. 我从一个新应用程序开始,并按照配方"使用 Rails 3.1 设置 html5-boilerplate"
  2. 当我启动该应用程序(在开发模式下)时,它运行良好。
  3. 当我在生产模式下启动时,出现以下错误:

    c:\apps\ruby\rails3\not>rails s -e 生产
    C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/html5-boilerplate-1.0.0/lib/html5-boilerplate.rb:1:in `' : 
      未初始化常量 Object::Compass (NameError)
        来自 C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    
  4. 然后我更改了 Gemfile (仅相关部分):

    组:资产做
      gem 'sass-rails', '~>; 3.1.4'
      gem '咖啡轨', '~>; 3.1.1'
      gem "指南针", '~> 0.12.alpha.0', :group => :生产
      gem 'html5-boilerplate', :group =>; :生产
      gem 'uglifier', '>= 1.0.3'
    结尾
    

对我来说,解决方案的相关部分是表示 compasshtml5-boilerplate 附加参数 :group =>; :生产

然后,我必须预编译资产,并且必须将 style.scss 更改为 style.css.scss,但这是一个小小的调整。在开发和生产模式下测试了该应用程序,似乎没有错误。

First my apologies for adding another answer, but I think the history is helpful for others.

I tried again (thank's to the comment of @theanym) to create a new application with rails 3.1.1, html5-boilerplate, compass, sass and haml, and I found a working solution for development and production mode.

These are the steps I have taken:

  1. I started with a new application and followed there the recipe "Setup html5-boilerplate with Rails 3.1".
  2. When I started the application (in development mode), it worked nicely.
  3. When I started then in production mode, I got the following error:

    c:\apps\ruby\rails3\not>rails s -e production
    C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/html5-boilerplate-1.0.0/lib/html5-boilerplate.rb:1:in `<top (required)>': 
      uninitialized constant Object::Compass (NameError)
        from C:/apps/ruby/ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
    
  4. I then changed the Gemfile (only the relevant part):

    group :assets do
      gem 'sass-rails',   '~> 3.1.4'
      gem 'coffee-rails', '~> 3.1.1'
      gem "compass", '~> 0.12.alpha.0', :group => :production
      gem 'html5-boilerplate', :group => :production
      gem 'uglifier', '>= 1.0.3'
    end
    

The relevant part of the solution for me was to denote for compass and html5-boilerplate that additional argument :group => :production.

I then had to precompile the assets, and had to change style.scss to style.css.scss, but that was a minor tweak. Tested the application both with development and production mode, and there seems to be no error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文