/base-rails-heroku

Proyecto base a utilizar en heroku

Primary LanguageRuby

GEMFILE SETUP

Start gemfile: source ‘rubygems.org

gem ‘rails’, ‘4.2.2’ gem ‘sass-rails’, ‘5.0.2’ gem ‘uglifier’, ‘2.5.3’ gem ‘coffee-rails’, ‘4.1.0’ gem ‘jquery-rails’, ‘4.0.3’ gem ‘turbolinks’, ‘2.3.0’ gem ‘jbuilder’, ‘2.2.3’ gem ‘sdoc’, ‘0.4.0’, group: :doc

group :development, :test do

gem 'sqlite3',     '1.3.9'
gem 'byebug',      '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring',      '1.1.3'

end

group :test do

gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace',     '0.1.3'
gem 'guard-minitest',     '2.3.1'

end

group :production do

gem 'pg',             '0.17.1'
gem 'rails_12factor', '0.0.2'

end

  • Instalar con el comando bundle install –without production.

  • Después correr bundle update.

BOOTSTRAP SETUP

Bajo la linea gem ‘rails’ ‘4.2.2’ Añado la línea gem ‘bootstrap-sass’, ‘3.2.0.0’ Luego, creamos un archivo en stylesheets llamado custom.css.scss, con las siguientes líneas al principio: @import “bootstrap-sprockets”; @import “bootstrap”; Esto nos permite empezar a diseñar con bootstrap inmediatamente. La gemfile queda así:

source ‘rubygems.org

gem ‘rails’, ‘4.2.2’ gem ‘bootstrap-sass’, ‘3.2.0.0’ gem ‘sass-rails’, ‘5.0.2’ gem ‘uglifier’, ‘2.5.3’ gem ‘coffee-rails’, ‘4.1.0’ gem ‘jquery-rails’, ‘4.0.3’ gem ‘turbolinks’, ‘2.3.0’ gem ‘jbuilder’, ‘2.2.3’ gem ‘sdoc’, ‘0.4.0’, group: :doc

group :development, :test do

gem 'sqlite3',     '1.3.9'
gem 'byebug',      '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring',      '1.1.3'

end

group :test do

gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace',     '0.1.3'
gem 'guard-minitest',     '2.3.1'

end

group :production do

gem 'pg',             '0.17.1'
gem 'rails_12factor', '0.0.2'

end

FORCE SSL

In production, we go to config/environments/production.rb and we uncomment the line config.force_ssl = true

PRODUCTION WEBSERVER

We add gem ‘puma’, ‘3.1.0’ in the production gem group. The we need to enter bundle install. The next step is to create a file called config/puma.rb and fill it with this:

workers Integer(ENV || 2) threads_count = Integer(ENV || 5) threads threads_count, threads_count

preload_app!

rackup DefaultRackup port ENV || 3000 environment ENV || ‘development’

on_worker_boot do

# Worker specific setup for Rails 4.1+
# See: https://devcenter.heroku.com/articles/
# deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection

end

Finally, we need to make a so-called Procfile to tell Heroku to run a Puma process in production. The file must be in root path. touch Procfile and fill with:

web: bundle exec puma -C config/puma.rb

HEROKU SETUP

we have to have root to some action in a controller and we are ready! git push heroku heroku create heroku rename .…

And we are ready to deploy in HEROKU.