Andrey Morozov

TILJanuary 28, 2019by Andrey Morozov

Use gem Recorder for db log 💪

Gem Recorder tracks changes of your Rails models

For start use this library in Rails 5.2 you need add gem to the Gemfile:

gem 'recorder', github: 'jetrockets/recorder', branch: 'rails_5_2'


> bundle install

> rails g recorder:install

> rails db:migrate

And final step -- add to model:

include ::Recorder::Observer

recorder async: false

And it's all 🎉

For an example - logs can be issued in the representer:

Recorder::Revision.where(item: object).order(id: :DESC).limit(10).map do |revision|



    userId: revision.user_id,

    userEmail: revision.user&.email,

    change: changes_type(revision)



def changes_type(revision)

  if['changes'].include?('drive_file_id') &&['changes'].size > 4 &&['changes']['drive_file_id'].present?

    'Object updated & Document generated'

  elsif['changes'].include?('drive_file_id') &&['changes'].size == 4

    'Document generated'

  elsif['changes'].include?('number') &&['changes']['number'].nil?

    'Object created'


    'Object updated'



But of course this is an abstract example with my data 😏

TILJanuary 26, 2019by Andrey Morozov

Command for create zip archive without gem's 📁

class CreateZipCommand

  def call(files)

    # Create temp directory for files 

    tmp_dir = Dir.mktmpdir

    tmp_zip_path = File.join(tmp_dir, "")

    # Move files to the temporary folder you created above do |file|

      download_file(file, tmp_dir)


    # Go to the folder and archive the entire contents

    `cd #{tmp_dir} && zip #{tmp_zip_path} ./*`

    # Return zip path





=> "/var/folders/bk/0c864z710654sx555jpdpx9c0000gn/T/d20190126-7447-d27fpl/")

Most gems for working with archives eat a lot of memory when working with large files. This solution does not have these problems.

Make sure that the zip utility is installed on your computer - it don't work without it

TILJanuary 23, 2019by Andrey Morozov

Webhook integration in development with Ngrok 🚀

All begin when I’m using the Pipedrive (is a sales management tool designed to help small sales teams manage intricate or lengthy sales processes) webhook.

The solution was easy I just create an ngrok tunnel

> ngrok http 3000 

Session Status                online

Account                       Andrey (Plan: Free)

Version                       2.2.8

Region                        United States (us)

Web Interface       

Forwarding           -> localhost:3000

Forwarding           -> localhost:3000

and then sent the webhook to the generated address and it works. In local development I can user webhook from another api! It's work 🚀

To use it you need to do 4 steps:

  1. Register on ngrok

  2. Download ngrok from site

  3. Connect your account

  4. Run it 🚀


In addition, this service has a ngrok-tunel gem that allows you to fully integrate it with your application. But that's another story 💎