图像未在生产中加载

Images are not loading on production

我正在将 Rails 应用程序部署到 Digitalocean。我正在与 Apache 和 Passenger 合作。我能够 运行 我的应用程序在本地生产并且运行良好。我在 localhost 上遇到了同样的问题,但做了以下事情让它工作。我在本地使用 Webrick 服务器,在 Ubuntu 中使用 Apache。

安装了这些 gem:

therubyracer
execjs

我将此添加到 production.rb

config.serve_static_files = true
config.assets.compile = true
config.assets.precompile =  ['*.js', '*.css']

然后我做了

RAILS_ENV=production bundle exec rake assets:precompile

我在 Ubuntu 中尝试了同样的制作,一切看起来都很好,但图像。

这是我在 /etc/apache2/sites-available/metalmind.com.co.conf

中的内容
    <VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin something@hotmail.com
    ServerName metalmind.com.co
    ServerAlias www.metalmind.com.co
    DocumentRoot /home/luisjar/Metalmind_2/public
    <Directory "/home/luisjar/Metalmind_2/public">
    Options All
    AllowOverride All
    Require all granted
    </Directory>
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>

    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

在此感谢您的帮助。

要在生产环境中加载图像,您需要检查某些事项 -

1) 生成的 url 是什么,您看不到图像已加载(使用 firebug 查看 url 路径)

2) 你把图片放在哪里,是在images下还是在public文件夹下。

3) 您是否使用此命令预编译了用于生产的资产 (rake assets:precompile RAILS_ENV=production)

此外,在类似情况下,这些日志也很有帮助。