Wednesday, 25 January 2012

Rails Blog with Scaffolding

I think you have installed ruby and Rails correctly.

Otherwise please visit this links:
Click Here

then follow the steps:
To make a new application, all we do is "Rails new 'Our app name'".
The name of this application will be webblog.


$ rails new webblog


This will put the directory 'webblog' on our desktop with all the necessary structures already built inside.

Now we will remake our current directory webblog.

$ cd webblog

The next thing we will do is now generate the scaffold of our blog. This is why scaling rails applications is soo easy.

$ rails generate scaffold Blog title:string content:text
$ rake db:migrate
$ rm public/index.html


The first line will generate the application from the front-end to the backend. It's a pretty simple configuration that you can edit upon to really make 'better'. Then next line migrates the database to add the database table for the blog entries, and the last line gets rid of the default page when you open up localhost:3000.

Now we must go into config/routes.rb and edit the root directory. Add this code to your routes.
App::Application.routes.draw do
  resources :posts

  root :to => "blog#index"
end

Now go back to the command line to fire this code.

$ rails server

This will fire up the server to start your rails application. Now you have created a small 5 minute scaffolded Rails blog. Hope this get's you started up

No comments:

Post a Comment

Source base installation of php, mysql and apache in ubuntu/ linux

Compile and Install a LAMP(Linux/Apache/MySQL/PHP) Server from Source In the last post, I described the method to install a LAMP ser...