Browsed by
Month: March 2016

Puma vs. Unicorn

Puma vs. Unicorn

TL; DR – You should start using Puma.

Rails has switched the default server from Webrick to Puma in Rails 5!

It also supports Action Cable (one of the new features from Rails 5) and Basecamp said they’re using Puma in production.

I was wondering if Puma has been in fact better than Unicorn so I’ve read some blog posts about it:

Basically, the answer is yes – it is a bit better, but don’t wait for a huge improvement. I’d say it might be a good idea if you’re:

  • about to start a new project;
  • about to migrate your current project to Rails 5;
  • unhappy with your Rails 3 / 4 app server performance.
Aprenda a programar

Aprenda a programar

Parte I – Desenvolvimento de aplicações web

Primeiramente, assista esse vídeo:

Depois leia esse post:

Finalmente, entre nesse grupo para acompanhar as novidades ou para tirar dúvidas: Ruby on Rails Brasil.

Parte II – Desenvolvimento de aplicações iOS (iPhone, iPad, Apple Watch, Apple TV)

Entre nesse grupo (Slack): iOS Dev BR.

Qualquer dúvida, mande nos comentários abaixo :-)

Rake task to import a production DB dump

Rake task to import a production DB dump

Every now and then I need to write a script (rake task) to import a production database dump.

This is code I usually use:

require 'yaml'

namespace :db do
  desc 'Downloads and imports a production DB dump'
  task :import_production_dump do
    puts '➙ Generating production DB dump...'

    execute_on_server %(
      PGPASSWORD="`cat /var/www/project/current/config/database.yml | \
        grep password | awk '{ print $2 }'`" \
        pg_dump database_name -h -U user_name \
        --column-inserts --no-owner --no-privileges > backup.sql

    puts '➙ Downloading production DB dump...'
    system "scp #{server_user_and_host}:#{backup_file_name} ."

    puts '➙ Deleting production DB dump...'
    execute_on_server 'rm backup.sql'

    puts '➙ Cleaning your local DB...'
    %w(drop create).each { |task| Rake::Task["db:#{task}"].invoke }

    puts '➙ Importing production DB dump...'
    system "bin/rails db development < #{backup_file_name} > /dev/null"

    puts '➙ Removing local dump...'
    system "rm #{backup_file_name}"

    puts '➙ Done!'

  def execute_on_server(commands)
    system %(ssh -T #{server_user_and_host} << 'SSH'

  def server_user_and_host

  def backup_file_name

Let me know in the comments if you have a better solution! Perhaps a tiny gem? ツ