我遇到了在生产模式下加载某些资产的问题(Ubuntu 14.04)
我目前正在生产模式下运行带有乘客和apache的ruby,但是在http://address/site
上加载网站时出现了一些错误
ActionController::RoutingError (No route matches [GET] "/stylesheets/manifest.css"):
ActionController::RoutingError (No route matches [GET] "/javascripts/manifest.js")
我已尝试使用预编译资产(即使apache应提供静态文件而没有任何特殊问题)
RAILS_ENV=production rake assets:precompile
以及添加到production.rb
config.serve_static_files = true
OR
config.assets.compile = true
不幸的是,结果完全一样。
对我来说奇怪的是,如果我转到http://website:3000
,一切都完美无缺(css和js等等)..
有什么想法吗?
在config.assets.precompile = ['*.js', '*.css']
中添加initializers/assets.rb
和config.serve_static_files = true
中的production.rb
一起解决了一些问题。
现在它正确加载js / css但不加载svg / ttf。我也尝试添加它们,如:
config.assets.precompile = ['*.js', '*.css', '*.svg', '*.ttf', '*.gif']
但没有成功。
我看到的问题是,当它们位于http://website/assets/resource.svg
http://website/vocab/assets/resource.svg
加载资源
我还将http://website/vocab(chown -R www-data:www-data vocab/
)的所有者更改为www-data,因此Apache应该可以读取所有内容。
已添加资源 Gemfile的内容
source 'https://rubygems.org'
# TODO: The following dependencies could be included by the "gemspec" command.
# There is only one problem: gemspec puts the dependencies automatically to a
# group (:development by default). This is not what we need.
gem 'rails', '~> 4.2.8'
gem 'kaminari'
gem 'kaminari-bootstrap', '~> 3.0.1'
gem 'authlogic', '~> 3.4.2'
gem 'cancancan', '~> 1.10.0'
gem 'iq_rdf', '>= 0.1.15'
gem 'iq_triplestorage'
gem 'json'
gem 'rails_autolink'
gem 'faraday', '0.9.0'
gem 'faraday_middleware'
gem 'nokogiri', '~> 1.6.0'
gem 'linkeddata', '~> 1.1.2'
gem 'uglifier'
gem 'sass-rails', '~> 5.0.0'
gem 'bootstrap_form', '~> 2.2.0'
gem 'font-awesome-rails', '~> 4.3.0'
gem 'apipie-rails', '~> 0.3.5'
gem 'maruku', require: false
gem 'database_cleaner'
gem 'delayed_job_active_record', '~> 4.1.1'
gem 'carrierwave'
gem 'autoprefixer-rails', '~> 6.5.1.1'
gem "passenger", ">= 5.0.25", require: "phusion_passenger/rack_handler"
# database adapters
# comment out those you do don't need or use a different Gemfile
#gem 'mysql2', '~> 0.3.13'
gem 'sqlite3'
#gem 'pg'
group :development do
gem 'view_marker'
end
group :development, :test do
gem 'awesome_print'
gem 'better_errors'
gem 'web-console'
gem 'binding_of_caller', '0.7.3.pre1'
gem 'pry-rails'
gem 'pry-remote'
gem 'pry-byebug', '~> 1.1.2', platforms: :ruby_20
gem 'quiet_assets'
platforms :ruby do
gem 'hirb-unicode'
gem 'cane'
end
platforms :jruby do
gem 'activerecord-jdbcmysql-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3.13'
end
end
group :test do
gem 'capybara', '~> 2.4.0'
gem 'poltergeist', '~> 1.6.0'
gem 'webmock'
gem 'simplecov'
end
group :production do
end
group :heroku do
gem 'rails_12factor'
end
和Virtualhost的内容
<VirtualHost *:80>
<Directory /var/www/html/Skosmos>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LoadModule passenger_module /var/lib/gems/2.4.0/gems/passenger-5.1.4/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /var/lib/gems/2.4.0/gems/passenger-5.1.4
PassengerDefaultRuby /usr/bin/ruby2.4
</IfModule>
ServerName website.fr/
DocumentRoot /var/www/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias vocab/ /var/www/html/vocab/public
<Location /vocab>
PassengerBaseURI /vocab
PassengerAppRoot /var/www/html/vocab/
</Location>
<Directory /var/www/html/vocab/public>
Allow from all
Options -MultiViews +FollowSymLinks
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
答案 0 :(得分:0)
如果您在Windows上工作,请尝试安装并将此gem添加到Gemfile:
gem 'coffee-script-source', '1.8.0'
但只有这个版本..