luisjar
luisjar

Reputation: 127

Images are not loading on production

I'm deploying a Rails app to Digitalocean. I'm working with Apache and Passenger. I was able to run my app locally in production and worked fine. I had the same problem on localhost but did the following things to make it work. Locally I work with Webrick server and in Ubuntu with Apache.

Installed these gems:

therubyracer
execjs

I added this to production.rb

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

Then I did

RAILS_ENV=production bundle exec rake assets:precompile

I tried the same for production in Ubuntu and everything seems fine but the images.

This is what I have in /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 [email protected]
    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

I appreciate any help here.

Upvotes: 0

Views: 791

Answers (1)

Caffeine Coder
Caffeine Coder

Reputation: 1879

For images to load in production , you need to check certain things -

1) What's the url being generated where you see no image loaded (Use firebug to see the url path)

2) Where are you storing your images , is it under images or under public folder .

3) Have you precompiled you assets for production using this command (rake assets:precompile RAILS_ENV=production)

Also , in cases like these logs are quite helpful too .

Upvotes: 1

Related Questions