[ rails ] tags.map(&:name)

tags.map(&:name)

is the shorthand for

tags.map(&:name.to_proc)

Symbol#to_proc

The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation:

class Symbol
def to_proc
Proc.new do |obj, *args|
obj.send self, *args
end
end
end

Example

List all ids of User Model.

User.all.map(&:id)

[1,2,3,4]

ref : https://stackoverflow.com/questions/14143044/ruby-on-rails-active-record-query-each-collect-map

[ 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