Unicorn triggers mongoid error during assets precompile - ruby-on-rails

I have a rails app using Mongoid 3 running on Heroku. I've just updated it to use Unicorn. When I try to deploy it to Heroku I get the following error :
Running: rake assets:precompile
rake aborted!
undefined method `match' for nil:NilClass
/tmp/build_3nnbzpfmnjpns/vendor/bundle/ruby/1.9.1/gems/mongoid-3.0.21/lib/mongoid/sessions/mongo_uri.rb:49:in `initialize'
The full stacktrace can be found at http://pastebin.com/8YcJHEmS
But if I remove Unicorn from my Gemfile, the assets compilation succeeds. Looking into the Mongoid code, I can see that the error happens when the mongoid.yml file is getting parsed, but I can't figure out why Unicorn would cause that to fail.
My mongoid.yml file looks like this :
production:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
options:
skip_version_check: true
safe: true
And my Gemfile :
source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.11'
gem 'thin'
group :assets do
gem 'sass-rails', '~> 3.2'
gem 'coffee-rails', '~> 3.2'
gem 'uglifier', '>= 1.0.3'
gem "twitter-bootstrap-rails", '>=2.1.8'
gem "bootstrap_form"
end
gem "jquery-rails"
gem 'jquery-ui-rails', "3.0.1"
gem 'newrelic_rpm'
gem "httparty"
gem "resque"
gem "resque-loner"
gem "unicorn", "4.4.0"
gem "mongoid", "~> 3.0.0"
gem "mongo", "~> 1.7.0"
gem "bson", "~> 1.7"
gem "bson_ext", "~> 1.7"
gem 'less-rails', "~> 2.2"
gem 'therubyracer', '>= 0.11.1'
gem 'libv8', '~> 3.11.8'
gem 'devise', '~> 2.1.2'
gem 'devise_invitable', '~> 1.0.0'
gem 'bootstrap_form'
gem 'font-awesome-rails'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'kaminari'
gem 'mongoid_search'
Would you have any idea what's causing this ?

As I recently had this problem with Rails 4.0 and config.assets.initialize_on_precompile = false no longer has any effect with Rails 4.0 I spoke with Heroku support and was told to use this labs feature:
heroku labs:enable user-env-compile
I wasn't able to get an answer as to why the user environment is necessary only with Unicorn but it seems to be a Unicorn specific problem of some sort or Thin does something that prevents the entire app from booting.
The whole thing seems odd to me and smells of a problem with the way assets are pre-compiled.

Rails 3:
Try to turn off app initialization when pre-compiling assets:
# config/application.rb
config.assets.initialize_on_precompile = false
The line should already be there commented out.

Related

Can't deploy Rails app to Heroku due to scss

I am having an issue deploying my Ruby project to Heroku. I've searched around but haven't found a solution. My error is this:
remote: Sass::SyntaxError: Invalid CSS after "...able_background": expected ")", was ": #808080,"
remote: (in /tmp/build_4a9e512f14d76b318d2a93f5bcb4db07/app/assets/stylesheets/sass/admintable.scss:2)
remote: /tmp/build_4a9e512f14d76b318d2a93f5bcb4db07/app/assets/stylesheets/sass/admintable.scss:2
My scss code it is referring to is this on the second line:
$admin_table_colors:(
admin_table_background: #808080,
admin_table_header_background: #FF6347,
admin_table_header_font: orange,
admin_table_data_background: #808080
);
My gem file:
source 'https://rubygems.org'
gem 'rails', '4.2'
gem 'bcrypt', '3.1.11'
gem 'sass-rails', '4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'devise'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'omniauth'
gem 'omniauth-facebook'
gem 'turbolinks'
gem "pundit"
gem "tzinfo-data"
gem 'lodash-rails'
group :production do
gem 'pg'
end
group :test, :development do
gem "rspec-rails"
gem "capybara"
gem "launchy"
gem "rack_session_access"
gem "selenium-webdriver"
gem "better_errors"
gem "factory_girl_rails"
gem "simplecov"
gem "database_cleaner"
gem "pry"
gem "sqlite3"
gem "guard-rspec", require: false
gem "thin"
gem "dotenv-rails"
end
gem "bootstrap-sass", "~> 3.1.1"
gem "faker"
gem "friendly_id"
in my environments production file i have this set:
config.assets.compile = true
I do not have .css files only .scss. Should I convert them to css and remove my scss files for the deployment? Maybe my versions of the gems are not proper? Any insights to get that error out of the way would be great.
Your error message tells everything. You have a CSS syntax error on line #2 of app/assets/stylesheets/sass/admintable.scss.
Make sure the CSS there is valid. You can probably test locally to validate you've fixed the problem with rails assets:precompile.
try below code:
config/environments/production.rb
config.assets.compile = true
then run command:
RAILS_ENV=production rake assets:clean
RAILS_ENV=production rake assets:precompile
then push all compiles files and menifest file to heroku.
I found a solution to my problem. Although I believe my scss code is correct there was a problem in the precompile part. I had to change my map code in all my scss files one example of this is this code:
$admin_table_colors:(
admin_table_background: #808080,
admin_table_header_background: #FF6347,
admin_table_header_font: orange,
admin_table_data_background: #808080
);
I had to change it to:
$admin_table_colors:(
'admin_table_background' #808080,
'admin_table_header_background' #FF6347,
'admin_table_header_font' orange,
'admin_table_data_background' #808080
);
And then I had to change my map-gets. I had these map gets before:
map-get($map: $admin_table_colors, $key: admin_table_background);
And then changed it to:
map-get($admin_table_colors, 'admin_table_background');
I got it to deploy but however my site does not load and I do not know if that has anything to do with that change or it's something else.

Can't run R on Heroku with RinRuby

R is running okay in development on my Rails 4.2.6 app, but I can't get it to run in production on Heroku with the RinRuby gem (2.0.3). Heroku rejects an attempted push with the following errors (relevant parts of log):
-----> Installing node-v6.10.0-linux-x64
-----> Detecting rake tasks
sh: 2: Syntax error: Unterminated quoted string
sh: 2: Syntax error: Unterminated quoted string
/app/tmp/buildpacks/ f6d48d8a14fccbb19c0c0402fca224929d18e9ee042b3e204bc5992612e990d3b3a0fb1f9627b1a3bae11e9fa20dffc96e136bd734a2f3cf92a0d05bedd42cfe/lib/language_pack/helpers/rake_runner.rb:102:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
ensure you can run `$ bundle exec rake -P` against your app
and using the production group of your Gemfile.
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'rinruby'.
Gem Load Error is: No such file or directory - R
ruby_compile:15:in `<main>'
! Push rejected, failed to compile Ruby app.
! Push failed
I didn't have problems deploying to Heroku before installing RinRuby. I can successfully run
bundle exec rake -P command
against the app. I also tried placing
config.assets.compile =true
in the production environment, but that didn't solve the issue.
Don't know what's going on with the syntax errors; stumped on the RinRuby load error. To deploy R in production, I have the following files in the root directory:
.buildpacks:
http://github.com/virtualstaticvoid/heroku-buildpack-r.git#cedar-14-chroot
https://github.com/heroku/heroku-buildpack-ruby.git
init.r:
install.packages("ggplot2", dependencies = TRUE)
While researching, I found a similar but unanswered post: Install error of Rinruby on Heroku
What I'm I missing? How do I fix? More detail ... here's the gem file:
source 'https://rubygems.org'
ruby "2.2.4"
gem 'rails', '4.2.6'
gem 'bootstrap-sass', '~> 3.2.0.0'
gem "font-awesome-rails"
gem 'bcrypt', '~> 3.1.7'
gem 'cancancan', '~> 1.10'
gem 'devise'
gem 'rolify'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jquery-tablesorter'
gem 'momentjs-rails', '>= 2.8.1'
gem 'bootstrap3-datetimepicker-rails', '~> 4.7.14'
gem 'turbolinks'
gem 'jquery-turbolinks', '~> 0.2.1'
gem 'jbuilder', '~> 2.0'
gem 'jc-validates_timeliness'
gem 'validates_overlap'
gem 'time_difference'
gem 'simple_form'
gem "paperclip", "~> 5.1.0"
gem 'aws-sdk', '~> 2' # Amazon S3 cloud storage
gem 'chart-js-rails', '~> 0.0.9'
gem 'by_star', :git => "git://github.com/radar/by_star"
gem 'ransack'
gem 'kaminari'
gem 'private_pub'
gem 'thin' # serves Faye to handle publishing/subscribing asynchronously
gem 'twilio-ruby', '~> 4.11.1'
gem 'newrelic_rpm'
gem 'rinruby', '~> 2.0', '>= 2.0.3'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :development do
gem 'spring'
gem 'better_errors'
gem 'binding_of_caller'
gem 'figaro'
gem 'guard-rspec', require: false
gem 'seed_dump'
gem 'rails-erd'
gem 'brakeman', require: false
gem 'rubocop', require: false
gem 'rails_best_practices', require:false
gem "letter_opener"
end
group :development, :test do
gem 'pg'
gem 'rspec-rails'
gem 'factory_girl_rails'
end
group :test do
gem 'capybara'
gem 'capybara-email'
gem 'email_spec'
gem 'shoulda-matchers'
gem 'faker'
gem 'database_cleaner'
gem 'launchy'
gem 'rspec-activemodel-mocks'
gem 'poltergeist'
gem 'pry-rails'
end
group :production do
gem 'pg'
gem 'rails_12factor'
gem 'unicorn', '~> 4.8.3'
end
I successfully installed R on Heroku for my Rails app. In an effort to help someone else who may need this information, here are the steps I took to solve the problem:
Uninstalled the RinRuby gem, and installed rootapp-rinruby (https://rubygems.org/gems/rootapp-rinruby), a more recent fork of the RinRuby gem.
Modifed the int.r file:
my_packages = c("ggplot2")
install_if_missing = function(p) {
if (p %in% rownames(installed.packages()) == FALSE) {
install.packages(p, dependencies = TRUE)
}
else {
cat(paste("Skipping already installed package:", p, "\n"))
}
}
invisible(sapply(my_packages, install_if_missing))
Created a file called .r-version and put it in root directory with the following content:
3.4.0
Added this R buildpack (http://github.com/virtualstaticvoid/heroku-buildpack-r.git#cedar-14-chroot) to Heroku
Now when I push, the Heroku log reports....
R 3.4.0 successfully installed (with init)
I hope this information helps someone. Good luck!
For improved visibility, placing my comment as an answer:
In your Gemfile, replace:
gem 'rinruby'
with
gem 'rootapp-rinruby'

Rspec not working when rails_env=test

When I type this, everything works :
set rails_env=development
rspec spec/models/foo.rb
When I type this, my program get stuck with a deprecation warning :
set rails_env=test
rspec spec/models/foo.rb
->Rack::File headers parameter replaces cache_control after Rack 1.5.
I really need to launch my tests with rails_env=test Do you know what is going on?
Useful infos :
C:\dev>ruby --version
ruby 1.9.3p385 (2013-02-06) [i386-mingw32]
C:\dev>rails --version
Rails 3.2.12
My Gemfile :
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem 'sqlite3'
gem 'delayed_job_active_record', '= 0.3.3'
gem 'delayed_job', '= 3.0.5'
gem 'clockwork'
gem 'dj_mon'
gem 'libxml-ruby'
gem 'haml-rails'
gem 'log4r'
gem 'spreadsheet'
gem 'mail'
gem "axlsx", "= 2.0.0"
gem 'axlsx_rails'
gem 'ruby-prof'
gem 'test-unit', :require => "test/unit"
gem 'ruby-oci8', '= 2.1.4'
gem 'pg', :require => 'pg'
gem 'devise', '<= 2.2.3'
gem 'cancan', '<= 1.6.9'
gem 'validates_timeliness'
gem 'will_paginate'
gem 'nokogiri'
gem 'simplecov'
gem 'google_visualr'
gem 'thin'
gem 'workflow'
gem 'ruby-graphviz'
gem 'ruby-odbc'
gem 'rubyzip', "= 0.9.9"
gem "rspec-deep-ignore-order-matcher"
gem 'rspec'
gem 'awesome_print'
gem 'syntax'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails', '2.3.0'
group :test, :development do
gem "rspec-rails", "~> 2.0"
end
Update :
I updated my rails version to 3.2.13. The warning disapeared but my app is still stuck.
Update to rails 3.2.13 -- this was a bug fixed
https://github.com/rails/rails/pull/8812
Scroll to the bottom for the closed marker to see the note.
Fixed thanks to koffeinfre.
My test database config had a typo and I didn't know that I had logs into log/test.log.
Also, thanks to trh and Peter Alfvin for pointing out that the deprecation warning was fixed in rails 3.2.13.

Problems with asset precompile after updating to Rails 4

I am updating a Rails application from 3.2.12 to 4.0.0.beta1. I had a few minor issues but I could get the app running and all tests passing again. The problem is when I try to precompile all the assets for deployment, I get the following error:
vagrant#precise64:/vagrant$ RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
No such file to load -- bootstrap_flash_helper
/vagrant/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
Here is my Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.0.beta1'
gem 'pg'
gem 'github_api'
gem 'haml-rails'
gem 'jquery-rails'
gem 'simple_form', github: 'plataformatec/simple_form'
gem 'devise', github: 'plataformatec/devise', branch: 'rails4'
gem 'omniauth'
gem 'omniauth-github'
gem 'rails-backbone', '~> 0.9.10'
gem 'inherited_resources'
gem 'app_configuration'
gem 'unicorn'
gem 'foreman'
gem 'coveralls', require: false
group :assets do
gem 'sprockets-rails', github: 'rails/sprockets-rails'
gem 'coffee-rails', github: 'rails/coffee-rails'
gem 'therubyracer', platforms: :ruby
gem 'less-rails', github: 'metaskills/less-rails'
gem 'twitter-bootstrap-rails'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
end
group :test, :development do
# Debugging
gem 'pry'
gem 'debugger'
gem 'debugger-pry'
gem 'pry-nav'
gem 'pry-stack_explorer'
# Testing
gem 'timecop'
gem 'rspec-rails'
gem 'shoulda-matchers'
gem 'factory_girl_rails'
gem 'faker'
# gem 'cucumber-rails', '~>1.3.0', :require => false
gem 'database_cleaner', github: 'bmabey/database_cleaner'
end
The project is open source (work in progress), here is the github repository https://github.com/wolox/mgmt
Any idea about what I missing?
Thanks
I had a similar issue, then I found that group :assets doesn't exist anymore. After clonning your repo, I deleted the group :assets from your Gemfile, then your assets precompiled ok!
The :assets group is not loaded in the production environment by default, you can change this in your config/application.rb (https://github.com/Wolox/mgmt/blob/master/config/application.rb#L7 in your repo)
The advised practice is to compile your assets in development and then push the /public/assets directory to production once you're satisfied nothing breaks.
Use this line instead, and you should be fine:
RAILS_ENV=development bundle exec rake assets:precompile

Rails: undefined method 'paginates_per'

I'm installing a gem called Carrier https://github.com/stanislaw/carrier/blob/master/Gemfile into a Rails 3.2.1 app. It uses Kaminari and when I did bundle install after adding gem "carrier" to my Gemfile, it showed that I was using kaminari
Using kaminari (0.13.0)
However, when I tried to rake db:migrate, I got this error
rake aborted
undefined method `paginates_per' for Carrier::Chain(Table doesn't exist):Class
Can anyone suggest a fix for this? I've copied the gemfile from the Carrier gem below and the Gemfile for my own app below that
(Carrier gem Gemfile)
source "http://rubygems.org"
gem 'require_all'
gem 'kaminari'
gem 'unread'
gem 'sugar-high'
gem 'sweetloader'
group :development, :test do
gem 'rails', '~> 3.1.0'
gem 'unicorn'
gem 'mysql2'
gem 'devise'
gem 'rake-kit'
gem 'cutter'
gem "jeweler", ">= 1.6.4"
gem "rspec-rails", '>= 2.5'
end
group :test do
gem 'capybara'
gem 'factory_girl'
gem 'spork'
gem "launchy"
gem 'shoulda'
end
Gemfile for my starter app
source 'https://rubygems.org'
gem 'rails', '3.2.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'pg'
gem 'devise'
gem 'carrier'
# 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'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
Update These are the migrations it installed when I ran install:migrations
rake carrier:install:migrations
Copied migration 20120229055640_create_messages.carrier.rb from carrier
Copied migration 20120229055641_create_chains.carrier.rb from carrier
Update
I tried to reinstall it again on another git branch it this time I got a slightly different error when I ran rake db:migrate
rake aborted!
undefined method `acts_as_readable' for Carrier::Message(Table doesn't exist):Class
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
You appear to be missing some database backing for what Carrier is trying to do. From the Carrier readme, it looks like you need to run rake carrier:install:migrations before running db:migrate. Have you done that?

Resources