6. Basic Routes Example
/config/routes.rb
Bloggy::Application.routes.draw do
resources :posts
...
เรลส์จะสร้างเส้นทางบนเว็บแอพฯ หรือเราท์ (Routes)
ในคอนโทรลเลอร์ของ Posts ให้อัตโนมัติตามนี้
GET /posts - เชื่อมเข้ากับตัว index
GET /posts/:id - เชื่อมเข้ากับตัว show
GET /posts/new - เชื่อมเข้ากับตัว new
GET /posts/:id/edit - เชื่อมเข้ากับตัว edit
POST /posts - เชื่อมเข้ากับตัว create
PUT /posts/:id - เชื่อมเข้ากับตัว update
DELETE /posts/:id - เชื่อมเข้ากับตัว destroy
7. Basic Routes Example
/config/routes.rb ลองพิมพ์คําสั่งตามนี้
Bloggy::Application.routes.draw do
resources :posts rake routes
...
เรลส์จะสร้างเส้นทางบนเว็บแอพฯ หรือเราท์ (Routes)
ในคอนโทรลเลอร์ของ Posts ให้อัตโนมัติตามนี้
GET /posts - เชื่อมเข้ากับตัว index
GET /posts/:id - เชื่อมเข้ากับตัว show
GET /posts/new - เชื่อมเข้ากับตัว new
GET /posts/:id/edit - เชื่อมเข้ากับตัว edit
POST /posts - เชื่อมเข้ากับตัว create
PUT /posts/:id - เชื่อมเข้ากับตัว update
DELETE /posts/:id - เชื่อมเข้ากับตัว destroy
8. Basic Routes Example
/config/routes.rb ลองพิมพ์คําสั่งตามนี้
Bloggy::Application.routes.draw do
resources :posts rake routes
...
เรลส์จะสร้างเส้นทางบนเว็บแอพฯ หรือเราท์ (Routes)
ในคอนโทรลเลอร์ของ Posts ให้อัตโนมัติตามนี้
GET /posts - เชื่อมเข้ากับตัว index
GET /posts/:id - เชื่อมเข้ากับตัว show
GET /posts/new - เชื่อมเข้ากับตัว new
GET /posts/:id/edit - เชื่อมเข้ากับตัว edit
ไปเริ่มโค้ด
POST /posts - เชื่อมเข้ากับตัว create
ในคอนโทรเลอร์!
PUT /posts/:id - เชื่อมเข้ากับตัว update
DELETE /posts/:id - เชื่อมเข้ากับตัว destroy