the best way to set default value in ActiveRecord?

  1. default_scope will initialize values for new models, but then that will become the scope on which you find the model. If you just want to initialize some numbers to 0 then this is not what you want.
  2. Defining defaults in your migration also works part of the time… As has already been mentioned this will not work when you just call
  3. Overriding initialize can work, but don’t forget to call super!
  4. Using a plugin like phusion’s is getting a bit ridiculous. This is ruby, do we really need a plugin just to initialize some default values?
  5. Overriding after_initialize is deprecated as of Rails 3. When I override after_initialize in rails 3.0.3 I get the following warning in the console:


Cassandra is a highly scalable, eventually consistent, distributed, structured key-value store. It’s an alternative to SQL if you don’t need relational data structures. The best part is it’s super fast, distributed, decentralized architecture (no single point of failure) and its linearly scaling high write performance.

JSON format

There are just a few rules that you need to remember:

Else we come up with some error,

  • Objects are encapsulated within opening and closing brackets { }
  • An empty object can be represented by { }
  • Arrays are encapsulated within opening and closing square brackets [ ]
  • An empty array can be represented by [ ]
  • A member is represented by a key-value pair
  • The key of a member should be contained in double quotes. (JavaScript does not require this. JavaScript and some parsers will tolerate single-quotes)
  • Each member should have a unique key within an object structure
  • The value of a member must be contained in double quotes if it’s a string (JavaScript and some parsers will tolerates single-quotes)
  • Boolean values are represented using the true or false literals in lower case
  • Number values are represented using double-precision floating-point format. Scientific notation is supported
  • Numbers should not have leading zeroes
  • “Offensive”” characters in a string need to be escaped using the backslash character
  • Null values are represented by the null literal in lower case
  • Other object types, such as dates, are not properly supported and should be converted to strings. It becomes the responsability of the parser/client to manage this.
  • Each member of an object or each array value must be followed by a comma if it’s not the last one
  • The common extension for json files is ‘.json’
  • The mime type for json files is ‘application/json’


install couchdb on ubuntu

1. For couchdb, We need install  g++, erlang  and few adapter, so that couchdb will work smoothly.

Run below command form terminal,

$ sudo apt-get install g++

$ sudo apt-get install erlang-base erlang-dev erlang-eunit erlang-nox

$ sudo apt-get install libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool 

2. One we done with above installation, go to couchdb site and download coach db source file.

In a terminal, go to the folder where you have downloaded the file, extract and go to bin folder and run below commands.

$ ./configure
$ make
$ sudo make install

That's it, you done with coachdb installation. 

3.Next we need to start coachdb.
$ sudo couchdb
Apache CouchDB 1.2.0 (LogLevel=info) is starting.
Apache CouchDB has started. Time to relax.
[info] [<0.32.0>] Apache CouchDB has started on

4. Setting CouchDB as service
Run below command, that will set couchdb as service, When ever you start ubuntu.Couchdb will run as service.

$ sudo adduser --disabled-login --disabled-password --no-create-home couchdb
Adding user `couchdb' ...
Adding new group `couchdb' (1001) ...
Adding new user `couchdb' (1001) with group `couchdb' ...
Not creating home directory `/home/couchdb'.
Changing the user information for couchdb
Enter the new value, or press ENTER for the default
 Full Name []: CouchDB Admin
 Room Number []:
 Work Phone []:
 Home Phone []:
 Other []:
Is the information correct? [Y/n] Y

That's it.


Couch DB

CouchDB is a NoSQL, schema-free JSON document storage where JavaScript can access the database directly via HTTP with no middleware required!

1.JavaScript can access the database directly.

2.Browser-based GUI-> Play with your data, permissions and configuration right from the browser with CouchDB’s interface Futon.

3. Replication->Replication synchronizes two copies of the same database, allowing users to have low latency access to data no matter where they are. These databases can live on the same server or on two different servers—CouchDB doesn’t make a distinction. If you change one copy of the database, replication will send these changes to the other copy.

4.Security-> It also has database-level security. The permissions per database are separated into readers and admins. Readers can both read and write to the database but admins can also update the _design documents in a database.

5.validation-> The ability to validate inserts is built right into the database. You can combine with authentication to check to make sure the creator of the document is the one who is logged in.

6.Map/Reduce, List and Show-> You can take a bunch of documents, emit what you need and then reduce it down based on grouping relevant data.


REST – Representational State Transfer

REST is a concept that has been becoming very popular over the last few years, probably helped by the embrace it is receiving from the Rails community. When you do something RESTfully, you are performing actions on a resource. There are four basic actions that we might want to use on a resource: create it, read/view it, update it, and delete it. Sometimes this is called CRUD.

These four actions relate very nicely to four HTTP methods. Most web developers know about GET and POST. When we view anything on the Internet we are normally using the GET method to get something from the web server. When we fill in a form and submit data to the web server, we are usually using a POST method. I think that’s why we say ‘blog post’ because it is something we have literally POSTed to the Internet. But there are two other methods that we can use: PUT for when we get something, change it, and put it back, and DELETE for the last of the four CRUD actions.

So we apply the HTTP methods to the resource, indicated by a URI. The point is that the URI stays the same. Suppose i have a resource which is a task, uniquely identified by this URI:

If i GET that URI then i am viewing the task. If i PUT to it then i am updating it. If i send a DELETE request to that same URI then the server will know that i wish to delete the resource.