Rails, ember-cli-rails gem - ruby-on-rails-4

I tried to deploy a Rails & Ember-cli application to a VPS by Capistrano. I have integrated Ember-cli into Rails by using ember-cli-rails gem. The problem happens when Capistrano wants to do assets:precompile. Throwing an error like EmberCLI Rails requires your Ember app to have an addon. In this case, I am able to run assets:precompile on my local machine and on the server in the released directory without any problem. On server I have installed `Nodejs and NPM.
deploy.rb
lock '3.1.0'
set :application, 'APPLICATION NAME'
set :repo_url, 'GIT ADDRESS'
set :deploy_to, 'SERVER SIDE ADDRESS'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
end
end
end
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rvm'
set :rvm_type, :user
set :rvm_ruby_version, '2.2.0'
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Related Gems
gem 'rails', '4.2.0'
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'
gem 'capistrano-rvm', github: "capistrano/rvm"
any help would be appreciated.

I just fixed this problem by adding some tasks to my deploy.rb file.

desc "Build Ember addon"
task :build_ember_addon do
on roles(:app) do
execute "cd #{release_path}/frontend && /home/$USER/.nvm/versions/node/v0.12.2/bin/npm install --save-dev ember-cli-rails-addon#0.0.11"
end
end
desc "Intall npm"
task :npm_install do
on roles(:app) do
execute "cd #{release_path}/frontend && /home/$USER/.nvm/versions/node/v0.12.2/bin/npm install"
end
end
desc "bower install"
task :bower_install do
on roles(:app) do
execute "cd #{release_path}/frontend && /home/$USER/.nvm/versions/node/v0.12.2/bin/bower install --config.interactive=false"
end
end
before 'deploy:updated', 'deploy:build_ember_addon'
before 'deploy:updated', 'deploy:npm_install'
before 'deploy:updated', 'deploy:bower_install'

Related

Git Push to Rails Production Gives Response Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2 When Ruby Version is 2.2.2

I have seen this error all over the place, but none of the solutions I have found have helped to fix the issue. I am developing a rails app locally on a Mac and have set up a droplet on DigitalOcean to push the app to. My droplet is running Ubuntu 14 and i am deploying using a Git post-receive hook. This is the hook:
#!/bin/bash
GIT_DIR=/home/xxx/yyy_production
WORK_TREE=/home/xxx/yyy
export XXX_DATABASE_USER='xxx'
export XXX_DATABASE_PASSWORD='12345'
export RAILS_ENV=production
. ~/.bashrc
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
mkdir -p $WORK_TREE
git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log
# start deploy tasks
cd $WORK_TREE
bundle install
rake db:create
rake db:migrate
rake assets:precompile
sudo restart puma-manager
sudo service nginx restart
# end deploy tasks
echo "Git hooks deploy complete"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done
This is the output I get when I push:
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 444 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Master ref received. Deploying master branch to production...
remote: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2
remote: rake aborted!
remote: Bundler::RubyVersionMismatch: Your Ruby version is 1.9.3, but your Gemfile specified 2.2.2
I don't understand this at all, as I have installed ruby 2.2.2 and selected it using RVM. When I log on to the Ubuntu machine using ssh, I don't get any errors at all running bundler. Yet this is what it does when I run using my hook. I've been fighting with this for several days. Any help is greatly appreciated.
Just some additional info:
ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
rvm info
ruby-2.2.2:
system:
uname: "Linux mgots-app-01 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux"
system: "ubuntu/14.04/x86_64"
bash: "/bin/bash => GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.26.11 (master) by Wayne E. Seguin <wayneeseguin#gmail.com>, Michal Papis <mpapis#gmail.com> [https://rvm.io/]"
updated: "21 hours 6 minutes 30 seconds ago"
path: "/usr/share/rvm"
ruby:
interpreter: "ruby"
version: "2.2.2p95"
date: "2015-04-13"
platform: "x86_64-linux"
patchlevel: "2015-04-13 revision 50295"
full_version: "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]"
homes:
gem: "/home/xxx/.rvm/gems/ruby-2.2.2"
ruby: "/usr/share/rvm/rubies/ruby-2.2.2"
binaries:
ruby: "/usr/share/rvm/rubies/ruby-2.2.2/bin/ruby"
irb: "/usr/share/rvm/rubies/ruby-2.2.2/bin/irb"
gem: "/usr/share/rvm/rubies/ruby-2.2.2/bin/gem"
rake: "/usr/share/rvm/rubies/ruby-2.2.2/bin/rake"
environment:
PATH: "/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/usr/share/rvm/rubies/ruby-2.2.2/bin:/usr/share/rvm/bin:/home/carl/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/home/xxx/.rbenv/plugins/ruby-build/bin:/home/xxx/.rbenv/shims:/home/xxx/.rbenv/bin:/home/xxx/.rvm/gems/ruby-2.2.2/bin:/home/xxx/.rvm/gems/ruby-2.2.2#global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
GEM_HOME: "/home/xxx/.rvm/gems/ruby-2.2.2"
GEM_PATH: "/home/xxx/.rvm/gems/ruby-2.2.2:/home/xxx/.rvm/gems/ruby-2.2.2#global"
MY_RUBY_HOME: "/usr/share/rvm/rubies/ruby-2.2.2"
IRBRC: "/usr/share/rvm/rubies/ruby-2.2.2/.irbrc"
RUBYOPT: ""
gemset: ""
EDIT: posting further data per request
Gemfile
source 'https://rubygems.org'
ruby "2.2.2"
gem 'rails', '4.2.2'
gem 'pg'
gem 'bootstrap-sass', '3.3.5.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'font-awesome-rails'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
gem 'geocoder', '1.2.12'
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
group :production do
gem 'puma'
gem 'therubyracer', platforms: :ruby
end
rvm list
rvm rubies
* ruby-2.2.1 [ x86_64 ]
=> ruby-2.2.2 [ x86_64 ]
# => - current
# =* - current && default
# * - default
~/.bashrc
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
if [[ -n "$PS1" ]]; then
# Some code here... e.g.
export HISTCONTROL=ignoreboth
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session
On both your droplet and your mac, remove Gemfile.lock, make sure ruby -v responds with version 2.2, and do a bundle update.
These steps should reset everything. If they don't work, do a spring stop and reinstall bundler binstubs (if you use these tools).
Good luck!

No such file or directory - connect(2) for "/tmp/puma-status-1439451994589-14316"

I want to deploy my rails through Capistrano with Puma and Nginx. I have configured deploy.rb for puma and added required gems in gem files.
I am able to run initial deploy command as 'cap production deploy:initial' and able to access my rails app as described below.
But when I want to deploy some new changes or restart puma it fails and gave this error.
Gemfile:
gem 'capistrano', '~> 3.4.0'
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
# gem 'capistrano-passenger', require: false
gem 'capistrano-ext', require: false
gem 'capistrano-faster-assets', '~> 1.0.2'
Capfile:
# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/faster_assets'
require 'capistrano/rvm'
require 'capistrano/puma'
require 'capistrano/puma/workers'
require 'capistrano/puma/nginx'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
deploy.rb
# Puma Server Configuration
set :puma_threads, [4, 16]
set :puma_workers, 1
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"
# set :puma_conf, "#{shared_path}/puma.rb"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/capistrano`
puts "WARNING: HEAD is not the same as origin/capistrano"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
I have also used the below command to generate template for Puma and Nginx as below.
rails g capistrano:nginx_puma:config
I have run below commands to deploy my rails to EC2 instance (with Ubuntu)
cap production deploy:check
cap production puma:config
cap production puma:nginx_config
cap production deploy:initial
Now, I want to deploy some changes with below code.
cap production deploy
But I am getting the error as below.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu#54.175.134.149: bundle exit status: 1
bundle stdout: No such file or directory - connect(2) for "/tmp/puma-status-1439451994589-14316"
bundle stderr: Nothing written
SSHKit::Command::Failed: bundle exit status: 1
bundle stdout: No such file or directory - connect(2) for "/tmp/puma-status-1439451994589-14316"
bundle stderr: Nothing written
Tasks: TOP => deploy:restart
(See full trace by running task with --trace)
Please help!
Thanks
I found one workaround to fix this issue.
Just add the snippet below to your deploy.rb file.
It will override puma restart task.
Rake::Task["puma:restart"].clear_actions
namespace :puma do
task :restart do
on roles(:all) do
execute "RACK_ENV=#{fetch(:rails_env)} #{fetch(:rvm_binary)} #{fetch(:rvm_ruby_version)} do pumactl -S #{shared_path}/tmp/pids/puma.state restart"
end
end
end

Airbrake integration with Capistrano 3 with Rails 4 getting LoadError: cannot load such file -- airbrake/capistrano3

So, here is my Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
#
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/rails/assets'
require 'airbrake/capistrano3'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
Here's my deploy file:
# config valid only for Capistrano 3.1
lock '3.2.1'
set :application, 'my_app'
set :repo_url, 'git#github.com:org/my-app.git'
# Default branch is :master
set :branch, 'dev'
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/webapps/my_app'
# Default value for :scm is :git
# set :scm, :git
# Default value for :format is :pretty
# set :format, :pretty
# Default value for :log_level is :debug
# set :log_level, :debug
# Default value for :pty is false
# set :pty, true
set :deploy_via, :remote_cache
# Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/secrets.yml}
set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets}
# Default value for linked_dirs is []
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :bundle_flags, "--deployment --verbose"
# Default value for keep_releases is 5
# set :keep_releases, 5
set :ssh_options, { :forward_agent => true }
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart do
on roles (:app),:except => { :no_release => true } do
puts "\x1B[35m Restarting ... \x1B[0m"
execute "touch #{current_path}/tmp/restart.txt"
puts "\x1B[35m Done. \x1B[0m"
end
end
desc "Tag deployed release"
task :tag do
run_locally do
timestamp = Time.now.strftime("%Y_%m_%d_%H_%M_%S")
tag_name = "#{fetch(:stage)}_#{timestamp}"
latest_revision = fetch(:current_revision)
strategy.git "tag -f #{tag_name} #{latest_revision}"
strategy.git "push -f --tags"
info "[cap-deploy-tagger] Tagged #{latest_revision} with #{tag_name}"
end
end
after :publishing, :restart
after :restart, :cleanup
after :cleanup, 'deploy:tag'
#after 'deploy:finished', 'airbrake:deploy'
end
The issue is that when I run "cap production deploy:check" I get:
LoadError: cannot load such file -- airbrake/capistrano3
/home/dir/dev/my-app/Capfile:24:in `require'
/home/dir/dev/my-app/Capfile:24:in `<top (required)>'
/home/dir/.rvm/gems/ruby-2.1.0/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/home/dir/.rvm/gems/ruby-2.1.0/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/home/dir/.rvm/gems/ruby-2.1.0/bin/cap:23:in `load'
/home/dir/.rvm/gems/ruby-2.1.0/bin/cap:23:in `<main>'
/home/dir/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
/home/dir/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
If I change require 'airbrake/capistrano3'to require 'airbrake/capistrano' then I get NoMethodError: undefined methodinstance' for Capistrano::Configuration:Class`
Any ideas on how to fix it?
Thanks a lot!
BTW, here's my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'haml'
gem 'devise'
gem 'will_paginate', '~> 3.0'
gem 'thin'
gem 'faye'
gem 'aasm'
gem 'useragent'
gem 'mini_magick'
gem 'carrierwave'
gem 'airbrake'
group :development do
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'capistrano-rvm'
gem 'rspec-rails'
gem 'pry'
end
For googling folks, if you having this error after upgrading to latest Airbrake v5, there is a change
# Old way
# For Capistrano 2
# Capfile
require 'airbrake/capistrano'
# For Capistrano 3
# Capfile
require 'airbrake/capistrano3'
# config/deploy.rb
after 'deploy:finished', 'airbrake:deploy'
# New way
# For Capistrano 2
require 'airbrake/capistrano/tasks'
# For Capistrano 3
# Capfile
require 'airbrake/capistrano/tasks'
# config/deploy.rb
after :finished, 'airbrake:deploy'
https://github.com/airbrake/airbrake/blob/master/docs/Migration_guide_from_v4_to_v5.md#capistrano
same apply for Sidekiq, and other bunch of gems
Are you sure you have Airbrake 4.1.0 installed?

Unicorn and Gemfile are using different ruby versions when trying to run unicorn and Nginx on Digital Ocean

I am trying to run my Rails app through Nginx and Unicorn and when I try to run service unicorn start it tells me I fail with master failed to start, check stderr log for details. My Gemfile specifies ruby 2.0.0 and my ruby versions is 2.0.0p353. Unicorn seems to be using ruby 2.1.3. Is there any way to have unicorn use ruby 2.0.0 if it came default using 2.1.3.
When I tail the unicorn log:
/usr/local/rvm/gems/ruby-2.1.3/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:294:in `join'
/usr/local/rvm/gems/ruby-2.1.3/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.1.3/bin/unicorn:23:in `load'
/usr/local/rvm/gems/ruby-2.1.3/bin/unicorn:23:in `<main>'
/usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
E, [2014-10-31T20:55:57.551794 #15567] ERROR -- : reaped #<Process::Status: pid 30319 exit 1> worker=1
I, [2014-10-31T20:55:57.552041 #15567] INFO -- : worker=1 spawning...
I, [2014-10-31T20:55:57.553188 #30329] INFO -- : worker=0 spawned pid=30329
I, [2014-10-31T20:55:57.560300 #30331] INFO -- : worker=1 spawned pid=30331
I, [2014-10-31T20:55:57.587723 #30329] INFO -- : Refreshing Gem list
I, [2014-10-31T20:55:57.595703 #30331] INFO -- : Refreshing Gem list
E, [2014-10-31T20:55:57.940679 #30325] ERROR -- : Your Ruby version is 2.1.3, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
It looks like the error may be stemming from unicorn being located in /usr/local/rvm/gems/ruby-2.1.3/bin/ and my other gems in /usr/local/rvm/gems/ruby-2.0.0-p353/bin/.
My unicorn.conf looks like:
worker_processes 4
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/log/unicorn.log"
stdout_path "/home/unicorn/log/unicorn.log"
My unicorn file /etc/init.d looks like:
set -e
NAME=unicorn
DESC="Unicorn web server"
. /lib/lsb/init-functions
if [ -f /etc/default/unicorn ]; then
. /etc/default/unicorn
fi
PID=${PID-/run/unicorn.pid}
run_by_init() {
([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
}
exit_with_message() {
if ! run_by_init; then
log_action_msg "$1 Not starting."
fi
exit 0
}
check_config() {
if [ $CONFIGURED != "yes" ]; then
exit_with_message "Unicorn is not configured (see /etc/default/unicorn)."
fi
}
check_app_root() {
if ! [ -d $APP_ROOT ]; then
exit_with_message "Application directory $APP_ROOT is not exist."
fi
}
set -u
```
And the start function in that file:
```
start)
check_config
check_app_root
log_daemon_msg "Starting $DESC" $NAME || true
if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi
;;
Followed by the other commands like restart, stop, and so on.
And my Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.0'
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.4.0'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails'
gem 'jbuilder', '1.5.3'
gem 'bootstrap-sass', '3.1.1.0'
gem 'figaro'
gem 'rolify'
gem 'simple_form'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'rails_12factor'
gem 'pg'
gem 'notes-cli'
gem 'twitter-typeahead-rails'
gem 'gon'
group :development do
gem 'better_errors'
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
gem 'quiet_assets'
gem 'rails_layout'
gem 'mailcatcher'
gem 'rails-erd'
gem 'annotate'
end
group :development, :test do
gem 'factory_girl_rails'
gem 'rspec-rails'
gem 'faker'
gem 'pry'
gem 'rb-fsevent'
gem 'guard-rspec'
gem 'terminal-notifier-guard'
end
group :test do
gem 'capybara', '2.4.3'
gem 'database_cleaner'
gem 'email_spec'
end
I'd appreciate any help. I am new to Digital Ocean, Unicorn, and Nginx, with my only experience
in "deploying" is using Heroku.
I don't know, if this is the right way, but here how I solved the problem:
Kill all acitve unicorn processes. Do ps aux | grep unicorn and then kill -9 pid_number
Change the ruby version in /etc/default/unicorn as per How To Use the 1-Click Ruby on Rails on Ubuntu 14.04 Image. In particular this part:
PATH=/usr/local/rvm/rubies/ruby-2.1.3/bin:/usr/local/rvm/rubies/ruby-2.0.0-p353/bin:/usr/local/rvm/gems/ruby-2.0.0-p353/bin:/home/unicorn/.rvm/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:$ export GEM_HOME=/usr/local/rvm/gems/ruby-2.1.3 export
GEM_PATH=/usr/local/rvm/gems/ruby-2.1.3:/usr/local/rvm/gems/ruby-2.1.3
DAEMON=/usr/local/rvm/gems/ruby-2.1.3/bin/unicorn
Change the ruby version in /etc/init.d/unicorn, in particular this part:
export GEM_HOME=/usr/local/rvm/gems/ruby-2.2.1 export
GEM_PATH=/usr/local/rvm/gems/ruby-2.2.1:/usr/local/rvm/gems/ruby-2.2.1/gems:/usr/local/rvm/gems/ruby-2.2.1#global/gems
In my quotations the ruby versions don't match, because the one quote is from the article and the other is from my actual file, but just make sure that in all places you have the particular ruby version that you like.
Start unicorn: service unicorn start.
This assumes, you have already ran bundle install and have all necessary gems.

Rails 4 assets not loading in heroku after 'rake assets:precompile'

This is driving me insane! My app works properly on the local server, but when I uploaded to heroku, the css and js files didn't update. I read to precompile using rake assets:precompile to fix the issue, but then I uploaded to heroku again and now all my assets aren't loading at all! I've tried all variations of precompile, installed 12factor gem, turned some config settings from false to true, still not happening! When i look at the console, it says
[Error] ReferenceError: Can't find variable: jQuery
global code (application-38ccb09605964287831a37a0d9faf188.js, line 1)
but I do have Jquery! it works fine on local! I dunno what I'm doing wrong guys.
Gemfile
gem 'bootstrap-sass-rails'
gem 'rails_12factor', group: :production
gem 'rails', '4.0.0'
gem 'sqlite3', :group => [:development, :test]
group :production do
gem 'thin'
gem 'pg'
end
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
running $RAILS_ENV=production bundle exec rake assets:precompile made my heroku app work now. so i guess problem is fixed..
sorry, I don't have an explanation on why it works
Simply run
$ bundle exec rake assets:precompile
$ git add .
$ git commit -am "assets precompiled locally"
$ git push heroku master