Tuesday, 2 September 2014

Ruby on Rails tutorial with Blog application with database and CRUD

Creating a new Rails app:


after successful Rails installation in a machine do the below steps:

1. Open command prompt and type:

$ rails new my_app_name

2. Move to the current application directory:

$ cd my_app_name

3. Next Start web server as below:

$ rails server

4. Open your browser and goto:


Blog Application with Database and CRUD operations

Usage Specficiations:

– Blog is a discussion or information site published on the Web.

We will have two types of users
         –  The blog administrator and 
         – Blog users.

The blog administrator able to enter new posts.

Users able to visit the blog site, and enter comments for postings.

– The blog administrator can modify/remove any post or comment.

– Finally users should not be able to modify postings or other users’ comments.

Before we move on Please have a look at below videos:

Blog Application tutorial – Initial Steps to do

Our First step is to create the rails application as mentioned below: 

$ rails new blog  

Next, use the scaffold generator to create the MVC components needed for posts and comments: 

 $ rails generate scaffold post title:string \ body:text $ rails generate scaffold comment post_id:integer \ body:text

Now, create the database tables for post and comment using: 

$ rake db:migrate

If you type: 

$ rake routes a list of all the URLs currently recognized by your application will be provided.

At this stage all necessary files (model, view and controller) are generated successfully. But You didn't write even a single line of code. Framework done all the works for you.  

 Start the web server: 

$ rails server and point your browser to: http://localhost:3000

That's it. Your first blog application powered by ruby on rails is created.

What is next?
           We have just created a new application with basic design. Further more we need to work on design and validation part.

Where to work on validation and Design?
         Design works can be done at view files and Validation can be done at Model and controller files.

No comments:

Post a Comment