gpt4 book ai didi

css - 不良 Assets Heroku 链接

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:31 29 4
gpt4 key购买 nike

我在使用 Heroku 时遇到问题,当我尝试部署我的应用程序时,它没有运行 run assets:precompile而且我还没有在本地预编译我的 Assets ,我在 Git 中没有 list 文件。

我的应用程序正在使用 cedar,我运行 heroku stack

结果是
bamboo-mri-1.9.2<br/>
bamboo-ree-1.8.7<br/>
* cedar

在我部署的应用程序中,我得到 <link href="/stylesheets/application.css" media="all" rel="stylesheet" type="text/css" />代替 <link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" />在英雄库。在本地,当我运行 rails s在命令提示符下 Assets 没问题。

我的应用程序是用 Ruby on Rails 制作的。我的配置/application.rb

    require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
#require "sprockets/railtie"
require "rails/test_unit/railtie"

if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end

module Mongoapp
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.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer

# 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

# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
config.time_zone = 'Bogota'


# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]

# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true

# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
# config.active_record.whitelist_attributes = true

# Enable the asset pipeline
config.assets.enabled = true


# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
end
end

我的application.html.erb

    <!DOCTYPE html>
<html lang="es" xmlns:fb="http://ogp.me/ns/fb#" prefix="og: http://ogp.me/ns#">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= display_meta_tags%>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- fav and touch icons -->
<link rel="shortcut icon" href="assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
</head>
<%=render "layouts/header"%>
<body>
<% flash.each do |key,value|%>
<%if key==:notice%>
<%key=:info%>
<%end%>
<%if key==:alert%>
<%key=:error%>
<%end%>
<div class="alert alert-<%= key %>" id="flash_<%=key%>">
<div class="container"><%= value %>
<button type="button" class="close" data-dismiss="alert" onclick="document.getElementById('flash_<%=key%>').style.display='none';">×</button>
</div>
</div>
<% end %>
<%= yield %>
</body>
<%=render "layouts/footer"%>
</html>

我的环境/production.rb

Mongoapp::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

# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH

# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# See everything in the log (default is :info)
# config.log_level = :debug

# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )

# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false

# Enable threaded mode
# config.threadsafe!

# 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

config.action_mailer.default_url_options = { :host => 'inkognitmongo.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.com",
port: 587,
domain: "inkognitmongo.herokuapp.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"]
}

config.assets.precompile += %w( application.css bootstrap.js jquery.js jquery.easing.1.3.js raphael-min.js google-code-prettify/prettify.js prettify.js jquery.elastislide.js jquery.tweet.js jquery.prettyPhoto.js jquery.flexslider.js iview.js jquery-hover-effect.js animate.js custom.js .svg .eot .woff .ttf)
end

最佳答案

首先,将以下内容添加到您的 application.rb 以在 Heroku 上启用管道的预编译:

# config/application.rb
config.assets.initialize_on_precompile = false

然后,在您的 Heroku 控制台中(可通过 Heroku Toolbelt 从命令行键入 heroku run console 访问),使用以下命令手动预编译:

bundle exec rake assets:precompile

最后,通过键入 heroku restart 重新启动您的应用程序 - 您的 Assets 管道应该已正确预编译。

更新:

如果上述解决方案仍未设置正确的路径,则您的 list 文件导致默认 Assets 路径被标签助手覆盖。您可以通过从 public/assets/ 目录中删除 manifest.yml 文件来解决此问题,提交您的更改,然后重新部署到 Heroku。

关于css - 不良 Assets Heroku 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19056013/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com