我有一個主題,我經常在我的網站上使用。我一直試圖通過一個寶石加載CSS,JS和插件文件夾(包含在主題中)。使用寶石加載資產(遇到問題不會加載資產)
Sprockets::FileNotFound: couldn't find file 'phcthemes' with type 'application/javascript'
如果我拿出的JavaScript(CSS)此不執行,準確地顯示出來這樣在編譯的資產
*= phcthemes
我的想法應用程序是不承認的寶石,我試過使用isolate_namespace(現在註釋掉)也嘗試了幾種不同的配置,使用以下答案中的信息無濟於事。
主要應用application.css
*= phcthemes
主要的應用程序的application.js
// require phcthemes
LIB/phcthemers.rb
require "phcthemes/version"
module Phcthemes
class MyRailtie < Rails::Railtie
end
class Engine < ::Rails::Engine
# Isolate Namespace
#isolate_namespace Phcthemes
# Initialize Assets
initializer :assets do |config|
Rails.application.config.assets.precompile += %w{ application.js application.css }
Rails.application.config.assets.paths << root.join("app", "assets", "javascripts")
Rails.application.config.assets.paths << root.join("app", "assets", "stylesheets")
end
end
end
phcthemes.gemspec
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "phcthemes/version"
Gem::Specification.new do |spec|
spec.name = "phcthemes"
spec.version = Phcthemes::VERSION
spec.authors = ["BradPotts"]
spec.email = ["[email protected]"]
spec.homepage = "http://phcnetworks.net"
spec.summary = "PHCThemes"
spec.description = "PHCNetworks theme with mtdevise and assets built in."
spec.license = "GPL-3.0"
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.files = Dir["{app,config,db,lib}/**/*", "LICENSE", "Rakefile", "README.md"]
# Main Structure & Security
spec.add_dependency "rails", "~> 4.2.5.2"
# Development & Testing
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "bundler", "~> 1.11"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
end
感謝您的答案馬克斯,它看起來應該工作,但不因爲某種原因與我。順便說一句,感謝您的項目鏈接真的幫助我。我更新了我提出的更多信息和更改。將繼續在此工作。 – bradpotts
@bradpotts它看起來像你的問題中的css/js需要語句仍然是錯誤的,它應該是'* = require phcthemes'和'// = require phxthemes'。如果沒有等號表示依賴項未被加載。等號後的'require'這個詞也是必需的,無論是在CSS還是JS –
謝謝你的幫助。我做了改變。我仍然有同樣的錯誤,但我感到滿意,因爲它看起來是正確的,並使我朝着正確的方向前進。如果你注意到其他事情,請讓我知道。 – bradpotts