Sunday, June 18, 2017

Test Behavior vs Implementation

You might have heard that in Rails model:

      validates_presence_of :name
can be tested using helpers like:

should_validates_presence_of :name

The problem with this kind of testing is that it is tied to this specific implementation of validation. If you change the validation to use it's own custom object, this test will break. This is not a good idea.

Wednesday, June 14, 2017

Conversion Points

Conversion Points

Every time your audience is asked to take an action within your sales funnel some users fall off. The key to a highly profitable funnel is to optimize each one of these conversion points.
Let's see which conversion points matter most, how to optimize them, and the 4 main metrics you should track if you want to profit.
  • Lead Magnet
  • Opt-In
  • Email Followups (Open Rates)
  • Order Form Conversion
  • Upsell
Every single step in the sales process is a conversion point. Every kind of sales funnel has it's own conversion points. Take a look at your existing funnel and identify all the conversion points. Conversion rates in sales page is one of the conversion point in the sales process. But the entire sales process must be optimized. 

Key Metrics

  • Cost of Customer Acquisition 
  • Life-Time Customer Value      (Triple the initial sale, in two years or so).
  • Cost Per Lead 
You can buy PDF template at Graphic River  and use it to create PDF documents.

Wednesday, June 07, 2017

Possible Rack Cache Issue

I had to remove rack-cache to figure out why articles index page did not display all articles when a user clicked on a tag to get related articles.

First remove the rack-cache gem, delete rack-cache gem in Gemfile and run bundle. To troubleshoot this problem, in production.rb set:

config.assets.compile = true

In your development machine (not production) run:

bundle exec rake assets:precompile returned 1 instead of one of [0]

This gave a clue that there was a reference to rack-cache in application.rb.

rake assets:precompile --trace RAILS_ENV=production
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
LoadError: cannot load such file -- rack/cache Be sure to add rack-cache to your Gemfile
/Users/bparanj/.rvm/gems/ruby-2.3.1@lafon/ge


Remove    

config.action_dispatch.rack_cache = true from application.rb

Redeploy the code and from rails console production in the production machine, run:

Rails.cache.clear

to clear the cache. The problem turned out to be not related to rack-cache. At least one of the suspect has been ruled out. I temporarily disabled the find related articles by tag.

Monday, June 05, 2017

Tagging Multiple Models in Rails Notes

```ruby
class TagMultipleModels < ActiveRecord::Migration
  def change
    rename_column :taggings, :episode_id, :taggable_id
    add_column :taggings, :taggable_type, :string, :default => 'Episode'
    remove_foreign_key :taggings, :episodes
  end
end
```

rake db:rollback

StandardError: An error has occurred, all later migrations canceled:

Add a new migration for:     remove_foreign_key :taggings, :episodes

rails g migration remove_foreign_key_for_taggings


ActiveRecord::InvalidForeignKey


Delete teh new migration and create a new article instead of editing an existing record in an invalid state.


SELECT column FROM table WHERE column NOT IN
(SELECT intended_foreign_key FROM another_table)

select taggable_type from taggings where taggable_type NOT IN (select taggable_id from episodes);

Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails


Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`chico_development`.`taggings`, CONSTRAINT `fk_rails_18a01188f6` FOREIGN KEY (`taggable_id`) REFERENCES `episodes` (`id`)): INSERT INTO `taggings` (`taggable_type`, `tag_id`, `taggable_id`, `created_at`, `updated_at`) VALUES ('Article', 542, 4752, '2017-06-06 03:14:34', '2017-06-06 03:14:34')


Import data from production. Merge the last two new migrations to one migration:


brew install elasticsearch

==> Using the sandbox
==> Downloading https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.tar.gz
######################################################################## 100.0%
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_bparanj/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_bparanj.log
Plugins: /usr/local/opt/elasticsearch/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/opt/elasticsearch/libexec/bin/elasticsearch-plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Summary
  /usr/local/Cellar/elasticsearch/5.4.1: 100 files, 35.4MB, built in 1 minute 7 seconds


elasticsearch

org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/var/elasticsearch/elasticsearch_bparanj]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?


$ brew remove elasticsearch
$ sudo rm -rf /usr/local/var/elasticsearch
$ sudo rm -rf /usr/local/etc/elasticsearch

$ brew install elasticsearch

brew install elasticsearch
==> Using the sandbox
==> Downloading https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.1.tar.gz
Already downloaded: /Users/bparanj/Library/Caches/Homebrew/elasticsearch-5.4.1.tar.gz
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_bparanj/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_bparanj.log
Plugins: /usr/local/opt/elasticsearch/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/opt/elasticsearch/libexec/bin/elasticsearch-plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
==> Summary
/usr/local/Cellar/elasticsearch/5.4.1: 100 files, 35.4MB, built in 12 seconds
$elasticsearch

  Article Store (14.7ms)  {"id":5091,"exception":["Faraday::ConnectionFailed","Couldn't connect to server"]}
Completed 500 Internal Server Error in 50ms (Searchkick: 14.7ms | ActiveRecord: 9.6ms)


Rails.cache.clear if new production import does not show new episodes.