One of the things I dislike most of Open Source Applications, it is that are very difficult to continue since the code and way it is built, also it does not cover components; instead of building new entire application I would like to see how to build small reusable components which could be integrated on new applications. Today, we are going to explain how to create a slik “address book”.
1) Create the rails project:
As I am a fan of mysql database, I do create projects specifically for this database with the sentence:
rails -d mysql addressbook
2) Create main objects:
The base of the addressbook is the contact object which we are going to scaffold:
script/generate scaffold contact firstname:string lastname:string lastname2:string phone_id:integer address_id:integer photo_id:integer page_url:string title:string company_id:integer email_id:integer background:text comments:text author:string
As you can see the Contact is compound by other objects such as phone, address and photo. These objects are formed by several characteristics:
- lastname2 – For those countries where a second last name is used
- phone_id – Each contact can have multiple phone which forms an array of values
- address_id- The address could be multiple and build on an object with an array of values
- comments – It has an auto-complete feature
3) Create authentication:
We are going to create the authentication, so only authorized users can access to the application
script/generate scaffold user userName:string firstName:string lastName:string alias:string email:string password_salt:string password_hash:string
4) Setup the database:
We open the database.yml file where we insert the password of the root user or if we have leave it blank as default we do not have to enter it. In order to look it, install a mysql administration tool. There are plenty on the Internet.
We execute the rake command to create the database
And we create the first migration
Now we have created the contact object on the database.
On next chapter, we will create the rest of the subornidates objects and we will add plugins.