1

尝试在 Rails 2.3 应用程序中运行 Sprockets 2...

根据Pivotal的本指南安装 gem 并在 config.ru 中实现它之后

require 'config/environment' if !defined?(Rails) || !Rails.initialized?
require 'sprockets'

unless Rails.env.production?
map '/assets' do
  sprockets = Sprockets::Environment.new
  sprockets.append_path 'app/assets/images'
  sprockets.append_path 'app/assets/javascripts'
  sprockets.append_path 'app/assets/stylesheets'

  Sprockets::Helpers.configure do |config|
    config.environment = sprockets
    config.prefix      = "/assets"
    config.digest      = false
  end

  run sprockets
  end
end

map '/' do
  use Rails::Rack::LogTailer unless Rails.env.test?
  use Rails::Rack::Debugger unless Rails.env.test?
  use Rails::Rack::Static
  run ActionController::Dispatcher.new
end

然后我创建了 app/assets 并将 javascripts、images 和 stylesheets 目录从公共目录移到了 app/assets 中。在 app/assets/javascripts/application.js 我有:

//= require_tree .

在 app/assets/stylesheets/application.css 我有:

/* ...
*= require_self
*= require_tree .
*/

当然在布局中我有:

<%= stylesheet_link_tag "assets/application" %>
<%= javascript_include_tag "assets/application" %>

我的配置中缺少某些东西,我的任何资产都不会显示。有小费吗?

4

1 回答 1

4

所以我有同样的问题。我用我的解决方案写了一篇文章:http: //jaredonline.github.com/blog/2012/05/16/sprockets-2-with-rails-2-dot-3/

于 2012-05-16T22:37:42.750 回答