在资产管道路径中获取

在资产管道路径中获取

本文介绍了在资产管道路径中获取 Gem 供应商文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 gem,其中包含来自 bootstrap-sass 和 bootstrap 本身的样式表和 javascripts 的供应商目录.

I have created a gem with a vendor directory containing stylesheets and javascripts from bootstrap-sass and bootstrap itself.

目录结构是bootstrap-sass-gem/vendor/assets/javascripts

The directory structure isbootstrap-sass-gem/vendor/assets/javascripts

bootstrap-sass-gem/vendor/assets/样式表

bootstrap-sass-gem/vendor/assets/stylesheets

我在一个测试项目中需要 gem,但是每当我尝试从该 gem 中获取某些东西时,我都会收到 Sprockets::FileNotFound 错误.

I've required the gem in a test project but whenever I try to require something from that gem I receive a Sprockets::FileNotFound error.

例如,在 application.css 中我添加了 *= require bootstrap.bootstrap 位于 bootstrap-sass-gem/vendor/assets/stylesheets/bootstrap.scss ,因此我认为应该包含在资产管道中.

For instance, in application.css I added *= require bootstrap.bootstrap is located at bootstrap-sass-gem/vendor/assets/stylesheets/bootstrap.scss and so by my reckoning should be included in the asset pipeline.

我正在运行 RVM Ruby 1.9.2 和 Rails 3.1.

I'm running RVM Ruby 1.9.2 and Rails 3.1.

这是我的配置文件:

 $:.push File.expand_path("../lib", __FILE__)

 # Maintain your gem's version:
 require "bootstrap-sass-gem/version"

 # Describe your gem and declare its dependencies:
 Gem::Specification.new do |s|
    s.name        = "bootstrap-sass-gem"
    s.version     = BootstrapSassGem::VERSION
    s.authors     = ["James Smith"]
    s.email       = ["[email protected]"]
    s.homepage    = "http://www.smithware.co.uk"
    s.summary     = "The Bootstrap-sass project Gemified"
    s.description = "Description of BootstrapSassGem."

    s.files = Dir["{lib,vendor,rdoc}/**/*"] + Dir["*"]
    #s.test_files = Dir["test/**/*"]

    s.require_paths = ["lib/**/*"]

    # We are dependent on the asset pipeline in 3.1.0
    s.add_dependency "rails", "~> 3.1.0"

    # s.add_development_dependency ""
 end

推荐答案

问题出在我的 require_paths 变量上.正确的设置应该是:

The problem was with my require_paths variable.The correct setting should have been:

s.require_paths = ["lib"]

这篇关于在资产管道路径中获取 Gem 供应商文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:42