Tuesday, December 29, 2009

First Blog



(1). create new project
> rails -d mysql weblog ---> force to use mysql as database

(2). cd to project directory
> cd weblog
> sudo nano config/database.yml ---> make sure all details correctly state eg.password
& username for database

(3). create table into the database
> rake db:create

(4). change route inside routes.rb
> sudo nano config/routes.rb
= find this line #map.connect :controller => "welcome" ---> remove #sign and
change welcome to post
> rm public/index.html ----> make sure post page will be display for homepage

(5). create scaffold
> script/generate scaffold Post name:string title:string content:text
--> automatically create

(6). rake db:migrate ---> migrate table into database

(7). adding validation
> sudo nano app/models/post.rb
= class Post < ActiveRecord::Base
validates_presence_of :name, :title, :content
end
----> make sure this code inside post.rb

(8.) Edit page that we create early
> sudo nano app/views/posts/index.html.erb
= change all the following code
- for tag h1, change to The Ruby Web Blog Using CMD
- for tag Name , change to Namae
Title , change to Shogou
Content , change to Ganryou
- for tag <% for post in @posts %>, change @posts as @posts.reverse
---> to make sure new entry for blog will be at the top.
- for tag <%= h post.name %>, change post.name to post.name.capitalize
---> make sure author name will be capitalize.


p/s ---> i'm using nano instead of vim or gedit.. u have the right to use vim or gedit. ^_^

2 comments:

  1. peh mantap.. bole la aja gue pakai ror nnti heheh

    ReplyDelete
  2. huhu..
    xreti2...
    biasa je pun.

    ReplyDelete