Can't deploy Rails app to Heroku due to scss - ruby-on-rails

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.

Related

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'

All Heroku Commands Are Broken due to Ruby Version

Everytime I run a heroku command I receive this error:
Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2
This has been happening since I pushed several changes (adding sidekiq and making changes to my clock.rb file, also: a new model I need to migrate the db for)
Does anyone know why this might be happening? It only started after I added ruby '2.1.2' to the gemfile. But before that I was getting this funky segmentation fault error.
Here's my gemfile:
source 'https://rubygems.org'
ruby '2.1.2'
gem 'rails', '4.1.1'
gem 'pg'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'clockwork'
gem 'httparty'
gem 'omniauth-facebook'
gem 'parse-ruby-client'
gem 'parse_resource', '~> 1.8.0'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'sidekiq'
gem 'foundation-rails'
group :development, :test do
gem 'pry-rails'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'shoulda-matchers'
gem 'valid_attribute'
gem 'capybara'
gem 'dotenv-rails'
gem 'better_errors'
gem 'binding_of_caller'
end
group :production do
gem 'rails_12factor'
gem 'thin'
end
It's seems to related bundler issue. Go through here https://github.com/sstephenson/rbenv/issues/400 same sort of issue also here get fixed with :
# Rakefile
task :freedom do
Bundler.with_clean_env { sh "heroku" }
end
Hope this help you!
I had two applications using Ruby. In your terminal, change to the directory of the application, then check the Ruby version you are using. Update it appropriately.

twitter-bootstrap-rails not working on heroku

I am working on ROR app, the app is working fine on local host but when on heroku "http://niveshi.herokuapp.com/portfolio/create" bootstrap is not working and even javascript code is not working. This is my gem file :
source 'https://rubygems.org'
gem 'rails', '3.2.12'
gem "mongoid", "~> 3.1.0"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'less-rails'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'delayed_job_mongoid'
gem 'rb-readline', '~> 0.4.2'
gem 'mechanize'
gem 'debugger'
gem 'twitter-bootstrap-rails'
Any guesses where I am wrong.
Use this on production.rb
config.assets.compile = true
If it is not work Then do the following things.
rake assets:precompile it will generate assets file in your public folder, commit all those file then push the code into heroku server.
Try rake assets:precompile and then upload again to Heroku.
Done , actually this should be out of assets
gem 'sass-rails', '~> 3.1.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'less-rails'
I got the same problem fixed with adding
a. gem 'rails_12factor'
b. bundle exec rake assets:precompile

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

Unicorn triggers mongoid error during assets precompile

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.

Resources