dimanche 1 mars 2015

I need help to sort out problems of asset pipeline with my app

I need help to sort out problems of asset pipeline with my app. Can anyone have look at what I am missing? Thanks in advance.


I am using the following rails 3.2.13, ruby 1.9.3 (for development) and ruby 2.0.0 (for production on heroku). ( I am using a different version of ruby on production as a gem called bybosa could not be installed with the development version of ruby… I am not sure if this is the source of the problem. Probably not…).


I have precompile the assets locally running: bundle exec rake assets:precompile RAILS_ENV=production. The assets get precompiled well and placed in public/assets/ directory. However, this process runs with an error : "can't dump anonymous class" errors. This seems to be associated with sass and sprockets… but the compilation get completed with files placed in the public/assets directory. The original images, and the same image names with long hash extensions. I commit everything to git and deploy from git to heroku. Heroku does not run assets compilation as there is a manifest file in the public/assets directory.


The application gets deployed well, but the images are not served properly. CSS and JS are served. The styling of the layout is as expected at least. So no problem with CSS and JS (that I can note). Only two images are served. Other 10 images are not served. Heroku logs shows that the error 404 not found for those images. And the path for those images are /assets/image_name. The two images that are served have these paths /assets/image_name + hash(combination of letters and numbers produced by the asset pipeline during the precompile operation). When you inspect elements on the webpage, only those two images that get displayed have the long hash after the image name. All othe images do not have the hash… I wonder why the webserver is not able to find the other images. Why is the webserver not pointing to the images as precompile by the asset pipeline with the long hash extension?


In the development environment all images are well displayed. Here, images are referenced by their simple name (without the asset pipeline extensions).


The github app:http://ift.tt/1E6T367


My gemfile:



source 'http://rubygems.org'

ruby "2.0.0"

gem 'rails', '3.2.13'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development, :test, :production do
# gem 'sqlite3'
gem 'pg'
end


# Gems used only for assets and not required
# in production environments by default.
#group :assets do
# gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# gem 'twitter-bootstrap-rails'
# See http://ift.tt/MqZZdN for more supported runtimes
# gem 'therubyracer', :platforms => :ruby

gem 'uglifier', '>= 1.0.3'
#end
# Use SCSS for stylesheets
gem 'bootstrap-sass', '3.1.1.0'
gem 'sass-rails', '>= 3.2'

gem 'jquery-rails'

gem 'turbolinks'
gem 'rails_12factor', group: :production
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

# Refinery CMS
gem 'refinerycms', '~> 2.1.0'

# Optionally, specify additional Refinery CMS Extensions here:
gem 'refinerycms-acts-as-indexed', '~> 1.0.0'
gem 'refinerycms-blog', '~> 2.1.0'
gem 'refinerycms-inquiries', '~> 2.1.0'
gem 'refinerycms-search', '~> 2.1.0'
gem 'refinerycms-page-images', '~> 2.1.0'
gem "refinerycms-news", '~> 2.1.0'
#gem 'refinerycms-portfolio', :git => 'git://github.com/refinery /refinerycms-portfolio.git', :branch => '2-0-stable'


gem 'refinerycms-videojs' #gem 'refinerycms-memberships', '2.0' #gem 'refinerycms-calendar', '~>2.0.0' #gem 'refinerycms-bootstrap', :github => 'fernandoaleman/refinerycms- bootstrap', :branch => 'master' group :development do gem 'jazz_hands' end


My config/application.rb file:

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 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 Renaissance2
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"

# 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'
config.assets.initialize_on_precompile = true
end
end


My config/environment/production.rb



Renaissance2::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 = true

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true

# 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

#for heroku
config.action_dispatch.x_sendfile_header = nil
# 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://ift.tt/rzONfP"

# 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
if config.respond_to?(:action_mailer)
# config.action_mailer.raise_delivery_errors = false
end

# 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

# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end


What I have tried without success:



  1. I tried to precompile the assets many times, but nothing changes

  2. I tried to disable the use of the asset pipeline in the production, but it did not change anything

  3. I tried suggestions on this stackoverflow issue: Rails 3.2.13 - Assets are not displayed in production Without success

  4. I have also looked at this heroku support page:http://ift.tt/1dF7kYS


Aucun commentaire:

Enregistrer un commentaire