[ activeRecord ] callbacks steps

(-) save

(-) valid

(1) before_validation

(-) validate

(2) after_validation

(3) before_save

(4) before_create

(-) create

(5) after_create

(6) after_save

(7) after_commit

ref : https://stackoverflow.com/questions/22952664/what-is-the-difference-between-before-create-and-after-create-and-when-to-us

[ Google Analytics ] create custom tracker

create

ga('create', 'UA-XXXXX-Y', 'auto', {'name': 'myTracker'});

declare custom dimension

ga('myTracker.set', {
'dimension1': 'Publish Date',
'dimension2': 'Author'
})

send event

ga('myTracker.send', 'pageview', {
'dimension1': post.publishDate,
'dimension2': post.author
});

ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers

[ Google analytics ] send custom dimension

declare custom dimension

ga('set', {
'dimension1': 'Publish Date',
'dimension2': 'Author'
});

send

ga('send', 'pageview', {
'dimension1': post.publishDate,
'dimension2': post.author
});

NOTE : our custom dimension are dimension1 and dimension2

TIPS : 

The location can be set

ga('set', 'location', 'http://foo.com/home?a=b');

ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#location

ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/events,

https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets

[ rails ] intercom-rails

Intercom auto-assign message to teammate

Click Intercom icon on the left hand side > click rules on the top-right bar.

intercom_route_rule

When creating a rule you can use any tag, segment or attribute about a lead, user or company, along with any information about the message.

Adding attribute to Intercom

adding-attribute-intercom.png

ref : https://docs.intercom.com/configure-intercom-for-your-product-or-site/customize-intercom-to-be-about-your-users/send-custom-user-attributes-to-intercom

ref : https://docs.intercom.com/recorded-intercom-demos/live-chat-with-visitors-and-customers,

https://docs.intercom.com/responding-to-users-and-visitors/work-as-a-team/assign-conversations-to-teammates-and-teams

NOTE : Need to subscribe `Standard` plan

assignment-respond-plan.png

ref : https://github.com/intercom/intercom-rails ( generating Intercom javascript script tags for Rails ),

https://github.com/intercom/intercom-ruby ( Ruby bindings for the Intercom API ),

https://developers.intercom.com/reference,

https://docs.intercom.com/install-on-your-product-or-site/other-ways-to-get-started/integrate-intercom-in-a-single-page-app,

https://www.netguru.co/tips/how-to-integrate-intercom-with-ruby-on-rails

 

 

[ rails ] RESTful resources

photos#index

GET /photos

display a list of all photos

 

photos#new

GET /photos/new

return an HTML form for creating a new photo

 

photos#create

POST /photos

create a new photo

 

photos#show

GET /photos/:id

display a specific photo

 

photos#edit

GET /photos/:id/edit

return an HTML form for editing a photo

 

photos#update

PATCH/PUT /photos/:id

update a specific photo

 

photos#destroy

DELETE /photos/:id

delete a specific photo

 

ref: http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

[ lodash ] _.extend(destination, source) v.s. _.merge(destination, source)

TL;DR;

merge will merge object hierarchy from source to destination. While for extend/assign, it’s simple one level copy of properties from source to destination.

 

extend/assign

For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

merge

For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination.

ref : https://stackoverflow.com/questions/19965844/lodash-difference-between-extend-assign-and-merge,

https://makandracards.com/makandra/29599-underscore-lodash-how-to-extend-or-merge-into-a-new-object

[ carrierwave ] carrierwave_backgrounder

Installation

gem 'carrierwave_backgrounder'

 

config/initializers/carrierwave_backgrounder.rb

CarrierWave::Backgrounder.configure do |c|
c.backend :delayed_job, queue: :carrierwave, priority: 5
end

MyUploader

add include ::CarrierWave::Backgrounder::Delay in the  CarrierWave uploader file

class MyUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay

...
end

NOTE : carrierwave will be added to queue/priority column in delayed_jobs table.