1

I have hosted a LocomotiveCMS app on Heroku. I've thereafter been working directly on the Heroku MongoHQ database, and have completed the wesbite.

I've then set the development database on my local machine to connect to the MongoHQ database used by the HerokuApp, so the local machine uses the actual data that's on the web. But the assets (CSS and JS files ) donot get accessed properly. Even though I've set up AWS Credentials.

So, when I access the CSSS+JS files on my local machine, I get the files, but with no content, i.e. blank file. I also dont get the AWS links for the assets, as I was seeing on the Heroku server.

Is it something to do with asset precompilation. I have set up the Heroku exactly as described here: http://doc.locomotivecms.com/guides/hosting/heroku-hosting

The production.rb file is as follows:

Testapp::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.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address        => 'smtp.sendgrid.net',
      :port           => 25,
      :authentication => :plain,
      :user_name      => ENV['SENDGRID_USERNAME'],
      :password       => ENV['SENDGRID_PASSWORD'],
      :domain         => ENV['SENDGRID_DOMAIN']
    }

end
Deej
  • 5,334
  • 12
  • 44
  • 68

2 Answers2

1

Run this in your console

bundle exec rake assets:precompile

then push to git, then to heroku

ahmet
  • 4,955
  • 11
  • 39
  • 64
  • Thanks for the advice. I did the above, but still get the blank asset files. I searched within my app directory : testapp/public/sites/519.../theme/javascripts and I do not see the JS files that are on the MongoHQ server. Same for CSS. I guess this would be the case. In a nutshell the problem would be : how to import asset files from a remote MongoHQ database to our local MongoDB database that Locomotive CMS uses. – Sandeep Paul Jun 21 '13 at 19:53
  • 1
    You may need to just copy them over to your public folder within your app – ahmet Jun 22 '13 at 09:52
0

I understand why you have set the following to config.assets.initialize_on_precompile = false this makes your application run faster. However the ruby on rails guides states the following:

If you set config.assets.initialize_on_precompile to false, be sure to test rake assets:precompile locally before deploying. It may expose bugs where your assets reference application objects or methods, since those are still in scope in development mode regardless of the value of this flag.

So potentially this could be the route of your problem. Also if you want to include additional css and js you can add the following into the precompile array like so:

config.assets.precompile += ['admin.js', 'admin.css']

See following link for additional reading: Precompiling assets

Hope this helps

Deej
  • 5,334
  • 12
  • 44
  • 68
  • Hi David, Thanks for your response. Even after running bundle exec rake assets:precompile I dont get my theme assets. I guess the issue boils down to copying/importing theme assets from the remote MongoHQ database to the MongoDB one used by Locomotive. I assume theme assets are stored in a different manner than other content (content types, entries etc) – Sandeep Paul Jun 21 '13 at 20:16