Friday, September 19, 2014

wrong number of parameters 2 for in stylesheet_link_tag rails

This error occurs with an ambiguous error message. It does not show the line number of the source where the cause of the problem resides. This happened due to sass-rails dependency on sass gem. Since the sass gem was not declared in the Gemfile, the sass-rails upgraded sass gem to 3.4.4 which broke the application layout. By locking the sass gem to a lower version in the Gemfile:

gem sass, "~ 3.2.1"

The sass-rails picked up this version that works.

Monday, September 01, 2014

The Scientific Method of Troubleshooting

Notes from the presentation by Blithe Rocher.

Set of Techniques for Acquiring Knowledge.

1. Define the Problem
Expected behavior
Actual behavior
Criteria for success

2. Do Your Research
Know your environment
Read the literature
Make it fail

3. Establish a Hypothesis
4. Design the Experiment
Divide and conquer
Limit the variables
Try something weird
Hierarchy of Blame

4. Gather Data
Current status
Read the error message

5. Analyze Your Results
 Problem Solved?
Learn anything?
Understand the Why
Future Experiments
Embrace the Success

6. Keep a Good Lab Notebook
You won't remember
Logs aren't enough
Commit messages
Update the docs
Blog it
Share the knowledge

Friday, August 22, 2014

How to play with ActiveModel validators in the rails console

1. bundle open activemodel
2. Open the validator.rb file.
3. You can see the comments that shows you how to mixin the validators. Once you mixin, you can add any validator and define a dummy method for the attribute to play with it in the irb:

class Person
  include ActiveModel::Validations
  SSN_REGEX = /your ssn regex goes here/
  validates_format_of :ssn, with: SSN_REGEX
  def ssn   

4. Change the ssn method to invalid ssn to test your regex.

Thursday, August 21, 2014

How to install Exception Notification gem in Rails 4.1

1. Add the gem to Gemfile:

gem 'exception_notification'

bundle install

2. In config/environments/production.rb:

Whatever::Application.config.middleware.use ExceptionNotification::Rack,
  :email => {
    :email_prefix => "[Whatever] ",
    :sender_address => %{"notifier" },
    :exception_recipients => %w{}

3. Configure ActionMailer, in config/environments/production.rb:

I am using Sendgrid SMTP API so:

config.action_mailer.delivery_method = :smtp

If you have sendmail installed on the production server:

config.action_mailer.delivery_method = :sendmail

4. In production.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true

How to install pdftk on Mac OS

You can download the installer from

After installation, open a new terminal and check installation:

$ pdftk --version

pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit:
This is free software; see the source code for copying conditions. There is

Wednesday, August 20, 2014

How to create .ruby-version and .ruby-gemset in RVM

rvm --create --ruby-version use ruby-2.1.2@r42
Reference: Create .ruby-version and .ruby-gemset

How to install latest version of Rails

gem install rails --version=4.2.0.beta1

How to check if ElasticSearch is running

By default elastic search runs on port 9200.

$ curl http://localhost:9200
  "ok" : true,
  "status" : 200,
  "name" : "White Pilgrim",
  "version" : {
    "number" : "0.90.13",
    "build_hash" : "249c9c5e06765c9e929e92b1d235e1ba4dc679fa",
    "build_timestamp" : "2014-03-25T15:27:12Z",
    "build_snapshot" : false,
    "lucene_version" : "4.6"
  "tagline" : "You Know, for Search"

1. gem install rest-client

require 'rest-client'

$ irb
> require 'rest-client'
 => true
> x = RestClient.get('http://localhost:9200')
 => "{\n  \"ok\" : true,\n  \"status\" : 200,\n  \"name\" : \"White Pilgrim\",\n  \"version\" : {\n    \"number\" : \"0.90.13\",\n    \"build_hash\" : \"249c9c5e06765c9e929e92b1d235e1ba4dc679fa\",\n    \"build_timestamp\" : \"2014-03-25T15:27:12Z\",\n    \"build_snapshot\" : false,\n    \"lucene_version\" : \"4.6\"\n  },\n  \"tagline\" : \"You Know, for Search\"\n}\n"
> x['ok']
 => "ok"
> JSON.parse(x)
 => {"ok"=>true, "status"=>200, "name"=>"White Pilgrim", "version"=>{"number"=>"0.90.13", "build_hash"=>"249c9c5e06765c9e929e92b1d235e1ba4dc679fa", "build_timestamp"=>"2014-03-25T15:27:12Z", "build_snapshot"=>false, "lucene_version"=>"4.6"}, "tagline"=>"You Know, for Search"}

Tuesday, August 19, 2014

How to configure the secret_key_base in Rails 4.1

1. Define an environment variable in .bashrc or .profile on the server:

export SECRET_KEY_BASE='a long string generated by running rake secret'

2. In secrets.yml file :
secret_key_base=<%= ENV['SECRET_KEY_BASE'] %>

3. MyBlog::Application.config.secret_key_base = Rails.application.secrets.secret_key_base

Remember: After deployment all the old sessions will become invalid.

Monday, August 18, 2014

How to add lib directory to the load path in Rails 4.1

   Uncomment the line :  config.autoload_paths += %W(#{config.root}/lib) in application.rb