Feb07

Method Scaffold digunakan untuk membuat CRUD (Create, Update, Delete) dari suatu tabel
secara instant

untuk melakukan ini, daku memakai :

1.Cinta
2.Cinta
3.Cinta
4.Kata2 dari seorang RUDI (Ruby Jedi) : “May Ruby Be With U”
5.Instant Rails for Windows, Donlot Di Sini
6.RadRails, donlot di Sini

Okeh setelah bahan2 disiapkan, maka silahkan bwat Rails project di raidrails dan nyalakan service apache/webrick,mysql via instantRails (bagian ini cari ndiri, ntar deh kapan2 daku jelasin, skrng gi males, maklum SIBUK…….., sibuk ceting he he)

misalnya kita akan membuat CRUD dari tabel accounts, Pertama-tama kita bwat lalu konfigurasi datasenya dulu, keonfigurasi database ada di config/database.yml, silahkan ubah sesuai dengan settingan database anda

modelnya terlebih dahulu, caranya pada tab generators, pilih model lalu di sebelahnya ketik account (tanpa pake s) lalu ketika GO, pada console rail_apps> pilih ruby script/generate model account

Image Hosted by ImageShack.us

nah Rails akan secara otomatis membuatkan script untuk create table accounts, script tersebut berada di folder db, di aplikasi daku script tersebut bernama 001_create_accouts.rb, buka script tersebut lalu mari kita tambahkan field-field yang akan digunakan pada table accounts

here the script

class CreateAccounts < ActiveRecord::Migration
   def self.up
      create_table :accounts do |t|
         t.column :username, :string
          t.column :firstname, :string
         t.column :lastname, :string
         t.column :password, :string
      end
    end

   def self.down
       drop_table :accounts
   end
end

lalu save dan pada tab Rake Tasks(Sebelah Generators) pilih db:migrate lalu klik GO maka Ruby akan membuatkan tabel accouts di MySQL, nah jika pembuatan tabelnya telah berhasil, berikutnya adalah pembuatan scaffoldnya, pada tab Generators pilih scaffold lalu di sebelahnya ketikan account dan klik GO, maka account controller, accout view dan accout testing telah terbuat

dan scaffolding telah selesai sampai di sini, silahkan liat keajaibannya di http://localhost:3000/accounts/list (diasumiskan aplikasi rails anda ada di host localhost & port 3000)

Komentar

Trackback: Use this URI to trackback this entry. Use your web browser's function to copy it to your blog posting.

Gravatar: You can have a picture at the top of each your comments by getting a Gravatar

Belum ada komentar.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.