Rails: CRUD dengan nested resources

Standard

Catatan singkat dari Rails nested resources.

Dalam hal ini digunakan dua resources, yaitu posts dan comments.
[github file = “/spondbob/nested-resources/blob/master/config/routes.rb” start_line = “2” end_line = “5”]

Setelah model disiapkan, kini beralih pada controller comments. Tambahkan fungsi untuk mendapatkan parent resource nya
[github file = “/spondbob/nested-resources/blob/master/app/controllers/comments_controller.rb” start_line = “76” end_line = “82”]
dan perubahan pada proses penyimpanan
[github file = “/spondbob/nested-resources/blob/master/app/controllers/comments_controller.rb” start_line = “26” end_line = “40”]

Terakhir untuk view, ubah link pada comment
[github file = “/spondbob/nested-resources/blob/master/app/views/comments/index.html.haml” start_line = “16” end_line = “19”]
[github file = “/spondbob/nested-resources/blob/master/app/views/comments/_form.html.haml” start_line = “0” end_line = “1”]
dan untuk link yang terdapat pada edit.html.haml dan new.html.haml
[github file = “/spondbob/nested-resources/blob/master/app/views/comments/edit.html.haml” start_line = “4” end_line = “7”]

References:

Leave a Reply