The rest of this series can be found here.
This post is a combination of days 4–5; I tried to build the app from scratch by memory but ended up following the getting started guide again somewhat, with modifications as necessary.
I initially set up the
todos model with just title and notes and forgot the boolean “completed” field. I ran
$ rails generate model Todo title:string notes:text completed:boolean to add it, but got an error; running the same command with the
--force option worked, but then
$ rake db:migrate had a bunch of error messages.
To fix the problem, I tried
$ rails generate migration add_boolean_to_todos completed:boolean, which succeeded, and then
$ rake db:migrate, which again produced a bunch of errors. Since I’m just starting into this app, I just deleted the
db/development.sqlite3 file to start from scratch and ran
$ rake db:migrate and it ran just fine. Now I know how to add a field after the initial database setup.
Handling and displaying booleans
I had forgotten to add the
completed parameter in
todos_controller.rb, so none of my todo items were saving the completion status. Once I added that, they saved, but I had to go back and edit the older items to add the completion status.
I also forgot to add the controller for handling updates (as I said, I’m trying to work through this from memory as much as I can). That caused an issue when I tried to edit an older item…it created a copy of the old item, leaving the old one intact.
The code is located on GitHub here.
Tomorrow I plan to add support for moving completed items to their own list, as well as adding a checkbox on the index for marking items as complete right there.
Once that’s done, I’ll work on setting it up live on my public server; that’s running Ruby 1.8.7 and Rails 2.3.18, so that may take some work to get working. I may have to take a rabbit trail and use Vagrant to set up a local dev environment that matches the live server…
To be continued.