SL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Make sure your application root config/initializer has omniauth file. 
RAILS_ROOT/config/initializers/omniauth.rb if yes double check is 
this file contain following code.

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, 'APP_ID', 'APP_SECRET'
If you have still same issues, U need to modify above code again,

If your app  running on linux OS add this code
Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, APP_ID, APP_SECRET, {:client_options => \
   {:ssl => {:ca_file => "/usr/lib/ssl/certs/ca-certificates.crt"}}}

If your app  running on window OS add this code

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET,\
   {:client_options => {:ssl => {:verify => false}}}

Now your application should run, if still problem. Start your server...


I am going to create a quick-start demo which would be helpful to  guide how to get an application set up with HAML.

App setup:

Rails 3.1, Mongodb,haml

1. rails new test_haml --skip active-record

will create a new app “test_haml” and skip active record libraries since i am using Mondodb so i will use mongoid.

2.Include some gems in gemfile.

gem ‘mongoid’, ‘2.0.0.beta.19’
gem ‘bson_ext’
gem “haml”

3. Now our’s next command will be

bundle install

because we need to update app with latest gem added in gemfile. Once the gems have installed we’ll need to run the Mongoid configuration generator so that it can create the configuration YAML file.

4.rails g mongoid:config

that will generate file mongoid.yaml some like
efaults: &defaults
host: localhost
# slaves:
#   – host: slave1.local
#     port: 27018
#   – host: slave2.local
#     port: 27019development:
<<: *defaults
database: test_haml_developmenttest:
<<: *defaults
database: test_haml_test

# set these environment variables on your prod server
host: <%= ENV[‘MONGOID_HOST’] %>
port: <%= ENV[‘MONGOID_PORT’] %>
username: <%= ENV[‘MONGOID_USERNAME’] %>
password: <%= ENV[‘MONGOID_PASSWORD’] %>
database: <%= ENV[‘MONGOID_DATABASE’] %>

5.git clone git:// lib/generators/haml

This will configure Rails 3 to use HAML generators instead of ERB  when we run any sacffold or controller because it is annoying to constantly remove .erb files, and or edit them into HAML syntax.

6. Finally we have need a small configuration setup that will assist in haml file generation.

we will add this bit of code in config/application.rb after "config.filter_parameteres +=[:password]" 
config.generators do |g|   g.template_engine :haml  end We completed with all setup, now need to run a sacffold and let's see how is working!!!!!!!!!!!!!!!!! 

7.rails generate scaffold Contacts name:string phone:string

8. rais server

take a look in view folder, you find all file in haml extention.


rake aborted! You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Consider using bundle exec.

rake aborted!
You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Consider using bundle exec.

(See full trace by running task with –trace)


1. Include below rake version in your gemfile

“gem ‘rake’, ‘0.9.2’ ”

2. Open rake file and include below line above ==>require ‘rake’

require ‘rake/dsl_definition’

3.In same rake file add below code above ==>app_name::Application.load_tasks

module ::app_name
class Application
include Rake::DSL

module ::RakeFileUtils
extend Rake::FileUtilsExt

make sure app_name will be your application name, just copy  app_name from ” app_name::Application.load_tasks”

Mongodb queries

Here is the some important frequently used mongodb queries.

After running mongodb server(mongod) and  interactive shell(mongo),  Our’s first command should be

1. help

->Which will show a lot  of useful command that is helpful at any instance working with mongodb.;

->It is database level help command that will show some of data level command.


-> This command will show database level methods.

All above command is basic mongodb command.

How to create database?

1. use databasename;

In my case it is “use mongotest”,  here USE  is command to create database and  mongotest is database name. It is one of the nice feature of mongodb if there will be no database with this particular name, will create new database else use(move) to exiting database.

 Create table!!!!!!!


Fetch data from tables!!!!!!!!!!

1. db.tablename.find();

return data of table.


return methods it self.

Create another record!!!!!!!!!


this is another way of creating new record and saving as an object.

Fetch particular record from tables !!!!!!!!!!


N.T. -> Search option is case sensetive.

find record using id

> db.contacts.find({_id:ObjectId("4ea3aa28eaaf3871b0549dfa")});
{ "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
 "name" : "ankit", "phone" : "09533607506" }

Update particular record into tables !!!!!!!!!!

-> there is two way to update table

1. Using save()->this is one of nice feature to mongodb, if there will already row in table it will update with new attribute else will create new record.

2. Using update()->will only update exiting record.

find record using object

> x = db.contacts.findOne({"name":"ankit"});
        "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
        "name" : "ankit",
        "phone" : "09533607506"
Now we have object x with reference of contacts table.
> x
        "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
        "name" : "ankit",
        "phone" : "09533607506"

Now i am going to add new attribute email

> = ""
Let's see updated row 
> x
        "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
        "name" : "ankit",
        "phone" : "09533607506",
        "email" : ""

Now we fetch details from table

> db.contacts.find();
{ "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
 "name" : "ankit", "phone" : "09533607506" }
{ "_id" : ObjectId("4ea3b067eaaf3871b0549dfb"),
 "name" : "abhay", "phone" : "9932326589" }

table is not updated here, we need to update table.

Now try again
> db.contacts.find();
{ "_id" : ObjectId("4ea3b067eaaf3871b0549dfb"), 
"name" : "abhay", "phone" : "9932326589" }
{ "_id" : ObjectId("4ea3aa28eaaf3871b0549dfa"),
 "name" : "ankit", "phone" : "09533607506",
 "email" : "" }

Delete particular record from tables !!!!!!!!!!

> db.contacts.remove(x);
let's see row is there or not
> db.contacts.find();
{ "_id" : ObjectId("4ea3b067eaaf3871b0549dfb"),
 "name" : "abhay", "phone" : "9932326589" }
yah, this row is deleted

Introduction to mongodb

What is mongodb?

->MongoDB (from “humongous”) is an open source, scalable, high-performance, schema-free, document-oriented database written in the C++ programming language.

->MongoDB has a variety of features designed to bridge the gap between key/value stores and and traditional RDBMSes; some of these features are hoc querying

2. secondary indexes

3. replication

4. aggregation.

What is Ad hoc queries?

->In MongoDB, any field can be queried at any time. MongoDB supports range queries, regular expression searches, and other special types of queries in addition to exactly matching fields. Queries can also include user-defined JavaScript functions (if the function returns true, the document matches).

Queries can return specific fields of documents (instead of the entire document), as well as sorting, skipping, and limiting results.

What is secondary indexes ?

->By default MongoDB creates index on _id key in document. But when we ensure additional index (secondary like in InnoDB from MySQL) and query it after, engine scans it and then selective scan _id index to get documments offsets.

What is replication ?

->MongoDB supports master-slave replication. A master can perform reads and writes. A slave copies data from the master and can only be used for reads or backup (not writes).

MongoDB allows developers to guarantee that an operation has been replicated to at least N servers on a per-operation basis.

What is aggregatoin ?

->Mongodb database supports a couple of tools for aggregation,like group function similar to SQL’s GROUP BY.

e.g. count(), desticnt(), group()………..


Bin­ary JSON, is a bin­ary-en­coded seri­al­iz­a­tion of JSON-like doc­u­ments. Like JSON, BSON sup­ports the em­bed­ding of doc­u­ments and ar­rays with­in oth­er doc­u­ments and ar­rays.

BSON can be com­pared to bin­ary inter­change for­mats, like Proto­col Buf­fers. BSON is more “schema-less” than Proto­col Buf­fers, which can give it an ad­vant­age in flex­ib­il­ity but also a slight dis­ad­vant­age in space ef­fi­ciency (BSON has over­head for field names with­in the seri­al­ized data).


JSON (JavaScript Object Notation) is a lightweight data-interchange format.

-> JSON is text-based open standard designed for human-readable data interchange.

->A Web data publishing format that is designed to be both easily human — and machine — readable.

->Simple format for data exchange over the internet (used as an alternative to XML)

->The JSON is used for data interchange between programs, an area in which the ubiquitous XML is not too well-suited.

->it’s largely adopted and supported by the most part of programming languages.

->it’s a language-independent format..

->can be compressed in one line to reduce stream size.

->can represent the most part of standard objects.

->seamlessly integrates with JavaScript which makes JSON the standard for streaming data over AJAX calls.