Creating a sample application for creating,listing posts

Hi ..to all today i learned a how create listing, posting,deleting posts for a simple blog application..

$ rails new myblog

$ cd myblog

then we have change the normal welcome page of the ruby..to do this generate controller by

$ rails generate controller home index

now go to the file myblog/app/views/home/index.erb type this

<h1>Hello, Rails!</h1>

<%= link_to “My Blog” , posts_path %>

now go to /config/routes.db and do the following change in line

# You can have the root of your site routed with “root”

# just remember to delete public/index.html.

root :to => ‘home#index’

now delete default application page using command

$ rm public/index.html

now create scaffolding using the command

$ rails generate scaffold Post name:string title:string content:text

now run the create db and migrate command

$ rake db: create

$ rake db: migrate

now our application is ready with posts.

Start the server using

$ rails server

open your web browser and type in the address bar http://localhost:3000 now you can see the page like this after clicking the My blog link

Posts Index screenshot

Thanks to all…now you can create new posts and list the posts,edit,delete your posts..

Author: Balaji

Hi..My name is Balaji and i am working as a Senior Software Developer in India. I am interested in Shell scripts, python, erlang , linux kernel .

One thought on “Creating a sample application for creating,listing posts”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: