I have been having this pretty rough time with assets on production. It came down to me trying to override the sprokets helper module to try and see what was up... When I re-wrote it to the following:
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
It would not run. I tried it in my local environment, and it runs perfectly. Is there a reason the production environment would not allow my assets to render in digest form, but my local environment would? This is related to what this gent was asking...
Rails 4.0.3 generating incorrect asset paths with asset_sync
Here is the error I receive after trying to override that method (which doesn't have an error when running with RAILS_ENV=development):
ActionView::Template::Error (undefined local variable or method `digest_path' for #<#<Class:0x000001034a99e0>:0x000001034a81d0>):
Asset Gems in Gemfile for reference:
source 'http://rubygems.org'
# ruby '2.1.1'
gem 'rails', '4.0.4'
gem 'jbuilder', '~> 1.2'
gem 'devise'
gem 'devise_invitable'
gem 'figaro'
gem 'mysql2'
gem 'simple_form'
gem 'kaminari'
gem 'statistics'
gem 'possessive'
gem 'geocoder'
gem 'nokogiri'
gem 'asset_sync'
gem 'sprockets-rails', :require => 'sprockets/railtie'
gem 'ledermann-rails-settings', :require => 'rails-settings'
gem 'public_activity'
group :assets do
gem 'therubyracer'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'guard-bundler'
gem 'guard-rails'
gem 'quiet_assets'
gem 'rails_layout'
gem 'rb-fchange', :require=>false
gem 'rb-fsevent', :require=>false
gem 'rb-inotify', :require=>false
end
group :test do
gem 'email_spec', '>= 1.4.0'
gem 'launchy', '>= 2.2.0'
gem 'capybara', '>= 2.0.3'
gem 'database_cleaner', '>= 1.0.0.RC1'
gem 'cucumber-rails', '>= 1.3.1', :require => false
end
group :production do
gem 'rails_12factor'
end
gem 'rspec-rails', '>= 2.12.2', :group => [:development, :test]
gem 'factory_girl_rails', '>= 4.2.0', :group => [:development, :test]
gem 'teaspoon', '>= 0.7.4', :group => [:development, :test]
gem 'cancan', '>= 1.6.9'
gem 'rolify', '>= 3.2.0'
gem 'stripe-rails'
gem 'faker'
gem 'open4'
gem 'unf'
When I run this in development mode, it runs completely fine. When I run this through production mode (even with the same config file) it does not inherit the View properties like digest_path or asset_digest_path is null or manifest, etc.
module Sprockets
module Rails
module Helper
def compute_asset_path(path, options = {})
if digest_path = asset_digest_path(path)
path = digest_path if true # BUG: digest assets doesn't work on live, let's just bake it
path += "?body=1" if options[:debug]
File.join(assets_prefix || "/", path)
else
super
end
end
def asset_digest_path(path, options = {})
if manifest = assets_manifest
if digest_path = manifest.assets[path]
return digest_path
end
end
if environment = assets_environment
if asset = environment[path]
return asset.digest_path
end
end
end
end
end
end
module ActionView
module Helpers
module AssetUrlHelper
def compute_asset_path(source, options = {})
dir = ASSET_PUBLIC_DIRECTORIES[options[:type]] || ""
File.join(dir, source)
end
end
end
end
Hopefully this will help save my fellow programmer friends some head banging :D
I was uploading the files to S3, I didn't realize that the manifest wasn't loaded by Rails. You can have all your production settings right (like above and in other threads), but if you don't have the manifest.json file readable by Rails, it will still generate /javascript/* (example) urls.
I was still having trouble with multi_json gem's latest version, so I downgraded it to 1.7.8 and it works fine.
gem 'multi_json', '1.7.8'
That's so it can read the manifest.json file which rake assets:precompile creates.
There is a debate on this sprockets thread https://github.com/rails/sprockets-rails/issues/107 on whether your manifest file should be in git or just on a deploy script, do what suits you best, just make sure it is findable in:
/public/assets/manifest.json
or specifiy it yourself with
config.assets.manifest = '...'
That may or may not be depricated.
Cheers!
Related
I'm trying to install fat free crm with ruby on rails on Windows 7, but when I put the command
rake db:create RAILS_ENV=production
it says
rake aborted!
LoadError: cannot load such -- 2.1/pg_ext
Normally, it would say what gem I should install, but not in this case.
How can I solve this error?
Edit:
A friend of mine suggested to uncomment mysql2 and comment pg on the Gemfile file in the proyect like this:
gem 'mysql2'
#gem 'sqlite3'
#gem 'pg'
But now I get this:
Unable to load the EventMachine C extension; To use the pure-ruby reactor, requi
re 'em/pure_ruby'
C:/Ruby21/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': ca
nnot load such file -- 2.1/rubyeventmachine (LoadError)
Have any ideas of why this happends?
Here is my Gemfile:
source 'https://rubygems.org'
# Uncomment the database that you have configured in config/database.yml
# ----------------------------------------------------------------------
gem 'mysql2'
# gem 'sqlite3'
# gem 'pg'
# Removes a gem dependency
def remove(name)
#dependencies.reject! {|d| d.name == name }
end
# Replaces an existing gem dependency (e.g. from gemspec) with an alternate source.
def gem(name, *args)
remove(name)
super
end
# Bundler no longer treats runtime dependencies as base dependencies.
# The following code restores this behaviour.
# (See https://github.com/carlhuda/bundler/issues/1041)
spec = Bundler.load_gemspec( File.expand_path("../fat_free_crm.gemspec", __FILE__) )
spec.runtime_dependencies.each do |dep|
gem dep.name, *(dep.requirement.as_list)
end
# Remove premailer auto-require
gem 'premailer', :require => false
# Remove fat_free_crm dependency, to stop it from being auto-required too early.
remove 'fat_free_crm'
group :development do
# don't load these gems in travis
unless ENV["CI"]
gem 'thin'
gem 'quiet_assets'
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rvm'
#~ gem 'capistrano-chruby'
#~ gem 'capistrano-rbenv'
gem 'guard'
gem 'guard-rspec'
gem 'guard-rails'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end
end
group :development, :test do
gem 'rspec-rails', '~> 2'
gem 'headless'
gem 'debugger', :platforms => 'mri_19' unless ENV["CI"]
gem 'byebug', :platforms => ['mri_20', 'mri_21'] unless ENV["CI"]
gem 'pry-rails' unless ENV["CI"]
end
group :test do
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
gem "acts_as_fu"
gem 'factory_girl_rails'
gem 'zeus' unless ENV["CI"]
gem 'coveralls', :require => false
gem 'timecop'
end
group :heroku do
gem 'unicorn', :platform => :ruby
gem 'rails_12factor'
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 'uglifier', '>= 1.0.3'
gem 'execjs'
gem 'therubyracer', :platform => :ruby unless ENV["CI"]
end
gem 'turbo-sprockets-rails3'
It sounds like you are missing the pg gem from your Gemfile. Is it in the development group?
Can you post your Gemfile?
Uncomment #gem pg.
Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' is a separate error. Where did you get that Gemfile?
I'm trying to install bootstrap-sass-rails. I copied this line: gem 'bootstrap-sass-rails' into the assets group. I ran bundle install. I followed the directions on the README exactly, but Sass complained that it couldn't find 'twitter/bootstrap' - I fiddled around a bit with locating the file and then...
Here comes the confusing part -- the gem was installed fine (or so Bundler said). But now there's nothing in my /vendor/assets/stylesheets directory! I checked git status and no new Sass files (or anything else really) was changed except app/assets/stylesheets/application.css.scss and app/assets/javascripts/application.js! I thought maybe that gem was broken, but the same thing happened with bootstrap-sass.
Why aren't my gems being installed correctly?
Full Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'bson_ext'
gem 'nokogiri'
gem 'execjs'
gem 'therubyracer'
gem 'rb-readline', '~> 0.4.2'
gem 'jquery-rails'
gem 'simple_form'
gem 'mysql2'
gem 'chronic'
gem 'prawn-labels'
gem 'draper'
gem 'ruby-aaws'
gem 'bcrypt-ruby'
gem 'sass-rails', '~> 3.2'
group :assets do
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass-rails'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'quiet_assets'
gem 'thin'
end
group :development, :test do
gem 'bourne'
gem 'rspec-rails'
gem 'pry'
gem 'pry-doc'
gem 'pry-debugger'
gem 'pry-rails'
gem 'faker'
gem 'pdf-inspector'
gem 'guard-rspec'
gem 'guard-zeus'
gem 'guard-livereload'
gem 'debugger'
gem 'rb-fsevent' if RUBY_PLATFORM =~ /darwin/i
if RUBY_PLATFORM =~ /linux/i then
gem 'rb-inotify' # Filesystem changes
gem 'libnotify' # Desktop notifications
end
end
group :test do
gem 'factory_girl_rails'
end
For "bootstrap-sass-rails" gem, the actual js and css files are located in gem's directory. They won't be copied to /vendor. And other gems do the same unless they provide a special generate task.
These directories will be included in assets' path. So when you mention #import bootstrap, Rails know where to search the files.
When running autotest, I get the error Could not find ZenTest-4.7.0 in any of the sources. After viewing this article, I deleted gemfile.lock, ran 'bundle install', and then tried rerunning autotest. Now I get the error Could not find rake-10.0.3 in any of the sources. FYI, I am using RBENV, and I have no other problems running my app (rails c, rails s, rake, ...). Here is my gem file (btw, both "missing" files appeared in gemfile.lock):
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'rake'
gem 'pg', '0.13.2'
# Sidekiq handles background jobs, using threading
gem 'sidekiq', '>= 2.6.1'
# Need the following gems for sidekiq/web
gem 'slim'
# if you require 'sinatra' you get the DSL extended to Object
gem 'sinatra', :require => nil
gem 'heroku-api' # Need the API for scaling sidekiq
gem 'json'
gem 'premailer'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# Bundle the extra gems:
gem 'mechanize'
gem 'nokogiri'
gem 'spreadsheet'
gem 'xml-simple'
gem 'faker', '~> 0.3.1'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development do
gem 'rspec-rails'
gem 'ruby-debug19'
end
group :test do
gem 'rspec-rails'
gem 'ZenTest'
gem 'shoulda-matchers'
gem 'webrat', '0.7.1'
gem 'factory_girl_rails'
gem 'ruby-debug19'
end
gem 'geoip'
gem 'thin'
gem 'htmlentities'
I'm not 100% certain, but I think you just do:
gem install ZenTest
and probably
gem install autotest-rails
From within your application directory.
These guys are not managed by your gemfile and bundler
I'm trying to get carrierwave set up with carrierwave_backgrounder, delayed_job, and fog for storage on AWS S3.
Whenever I try to do anything in the console such as generate controllers, I am getting this error:
ruby-1.9.3-p194/gems/carrierwave_backgrounder-0.0.9/lib/carrierwave_backgrounder.rb:19:in `backend': wrong number of arguments (1 for 0) (ArgumentError)
The culprit seems to be my initializer file, backgrounder.rb, which is copied directly from the carrierwave_backgrounder github.
CarrierWave::Backgrounder.configure do |c|
# :delayed_job, :girl_friday, :sidekiq, :qu, :resque, or :qc
c.backend :delayed_job
end
If I comment that out, my generators and such start working. I set up delayed_job and carrierwave properly I believe. Here's my gemfile as well:
gem 'rails', '3.2.8'
gem 'pg'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'devise'
gem 'delayed_job_active_record'
gem 'carrierwave'
gem 'carrierwave_backgrounder'
gem 'fog'
gem 'rmagick'
Use latest git release for implement this.
Add this in your gemfile:
gem 'carrierwave_backgrounder', :git => "git://github.com/lardawge/carrierwave_backgrounder.git"
I tried to deploy an application.war file into webapps/ in the tomcat folder and started up the server. When i try to open http://localhost:8080/relConnections it shows on the screen that "something went wrong". I deleted the common index.html in the public folder in usual rails apps and tchanged the root to my home page.
When i see the log file it says the following:
"An exception happened during JRuby-Rack startup private method `gsub' called for nil:NilClass
--- System
jruby 1.6.7"
and three or four more excecption saying the same lines gsub nil:NilClass for all of those.
Here is my Gemfile
source 'http://rubygems.org'
gem 'jruby-jars', '1.6.7'
gem 'warbler', '1.3.2'
gem 'rails', '3.1.3'
gem 'rake', '0.9.2.2'
gem 'jruby-openssl', '0.7.5', :platforms => :jruby
gem 'json', '1.6.5', :platforms => [:jruby, :mingw, :mingw_19]
gem 'therubyrhino', :platforms => :jruby
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'activerecord-jdbc-adapter', '1.2.2'
gem 'activerecord-oracle_enhanced-adapter', '1.4.0'
gem 'mechanize', '1.0.0'
gem 'nokogiri', '1.5.0'
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :development do
gem 'ruby-debug-base', '0.10.4'
gem 'ruby-debug-ide', '0.4.17.beta8'
gem 'pry', '0.9.7.4'
end
group :test do
gem 'turn', '0.8.3', :require => false
gem 'minitest', '2.11.0'
gem 'timecop', '0.3.5'
end
gem 'jruby-pageant', '~>1.0.2'
gem 'net-ssh', '~>2.5.2'
And here is my warble.rb
Warbler::Config.new do |config|
#commented code
config.dirs = %w(app config lib log vendor tmp)
#more commented code
end
Let me know if iam missing any gems or anything else here.
Thanks
I think you may try to set the jruby version to 1.9. In the warble.rb
config.webxml.jruby.compat.version = "1.9"