我刚刚通过Capistrano部署了一个网站。
除了我的css和js没有加载到页面上的标记外,它全部都去了plav:
<link data-turbolinks-track="true" href="/assets/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/application.js"></script>
我有上述内容但没有任何内容被加载,我收到404错误。
它在staging.rb中我最困惑,因为这是我目前用于部署的内容。
我的config / application.rb我有这个:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Forge
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Enable the asset pipeline
config.assets.enabled = true
config.nav_lynx.selected_class = 'current'
end
end
在development.rb中我有:
Forge::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
config.assets.debug = true
end
在production.rb中我有:
Forge::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
# Set to :debug to see everything in the log.
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
在staging.rb中我有:
Forge::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
似乎当我执行cap staging deploy
时,它会编译资产,但在我的rails live app中,它们没有被加载。
任何人都可以指出我正确的方向,我在哪里出错了,我真的在这里敲打砖墙。
干杯
答案 0 :(得分:1)
在资产:预编译之后,您需要重新启动服务器,以便rails开始使用摘要服务,因为它在启动时查找已编译的资产。在您的情况下,应用程序最有可能在没有任何编译资产的情Capistrano不会开箱即用。
通过触摸tmp / restart.txt文件可以重新启动Passenger。要允许capistrano重新启动乘客,请创建自定义rake任务:
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
end
end
end
并将其挂钩到capistrano deploy.rb中:
after 'deploy:publishing', 'deploy:restart'
此外,您的rake任务可以改进以检查您的服务器是否正在运行,然后相应地返回退出代码(在使用jenkins / hudson运行cap deploy时很有用)。当触摸tmp / restart.txt后第一个请求进入时,这也将立即重新启动乘客。请记住将“主页上的某些单词”替换为可在html中找到的任何单词。
namespace :deploy do
desc 'Restart passenger without service interruption (keep requests in a queue while restarting)'
task :restart do
on roles(:app) do
execute :touch, release_path.join('tmp/restart.txt')
unless execute :curl, '-s -k --location localhost | grep "Some word on home page" > /dev/null'
exit 1
end
end
end
end