The Archives

Sayanee's blog 2005 - 2012. Checkout her latest blog!

Day 1 Cracking the CRUD

07 May 2011 on Learning

Hello everyone!

A couple of months ago, when I first started with Rails, I took a loooong time to get all the setup and configuration. So, fret not if this happens to you :) I still have a long way to go, but it seems some of the stuff do get easier! So, let’s see how’s the todo app for now…

Steps:

  1. Generate controller and model for Task with the functions of CRUD (Create, Read, Update, Delete)
$ rails generate controller Tasks index edit show new
$ rails generate model Task name:string userid:integer
  1. Remove file public/index.html
  2. Edit routes.rb to connect root to task/index and added general routing
TodoApp::Application.routes.draw do
root :to => "tasks#index"
resources :tasks
end
  1. Edit tasks\_controller.rb to include index, show, edit, destroy, create, new functions

**Referred tutorials: **

  1. a simple CRUD `. Create a blog with rails

Tools used:

  1. Stackoverflow for many similar questions & their answers
  2. Annonate Gem Rails Plugin to automatically add model comments

Concepts learnt:

  1. CRUD
  2. REST
  3. MVC

Tips & Tricks:

  1. Cut and Paste the error messages into Google or else!!!
  2. Advanced Google Search -> Select Past One Year to ensure latest version answers
  3. When deleting a file, do remove it from git as well
$ git rm file-to-delete.rb

Time Taken: 4 hours [it wasn’t even 4 hours when I first tried following a tutorial! It was around 10 hours :) ]

Fun Stuff completed: Todo now has the functions of CRUD (Create, Read, Update, Delete)

peer into the code, play with the app

Next Objective: Build a “Done” Column/field for each task with a checkbox to update it’s status when the task is completed!