图像未在生产时加载

时间:2015-06-05 13:41:56

标签: ruby-on-rails ruby apache digital-ocean

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

安装这些宝石:

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 个答案:

答案 0 :(得分:1)

要在生产中加载图像,您需要检查某些内容 -

1)在没有加载图片的情况下生成的网址是什么(使用firebug查看网址路径)

2)您在哪里存储图像,是在图像下还是在公共文件夹下。

3)您是否使用此命令(rake assets:precompile RAILS_ENV=production

预编译了资产以进行生产

此外,在这些日志的情况下也非常有帮助。