Ive finished Learning Rails 3 by O’Really, and now its time to experiment knowledge on a real project and I’ll be deploying to Red Hat’s OpenShift platform.
Searching trough my laptop code projects folder, I came out with a simple TODO task manager ive wrote once in C++. So it would be a good idea to bring that project back to life, this time as a web task managing service in Rails, allowing auth with OmniAuth.
The original C++ project was planned on a OOP point of view. You could create a “Task” object with its current ID number, Text string, Date ,and Time.
Every part of a task was made as a different C++ class. Eash one cointains its validation on the constructor.
And then saved the tasks to sqlite or exporting them as a plain text that you could share or read again on the app.
So, back to business, I’m trying to adapt that little app into something more complex in Rails using MVC.
I thought about adding a Scaffolding that brings the form to fill the task’s text field and pass it to the Controller.
The controller will set current date and time, and ID is set by default when saving to the DB.
Validations should go on the model, and I’ll create a migration to build a table upon that fields.
As I’ll be adding multiuser support with OmniAuth, (so every user could save his own tasks), I should create a new DB table, with users info.
But should I create a new task table for each user, and then mapping them to the users table?
Or just create one task table and drop every user’s tasks in there and then mapping all there?
I cant figure out a good with saving user tasks to the db.
Any ideas?
Thanks in advance
This is assuming that a User can have many tasks, but a Task can belong to only one user.
You’ll have one
taskstable and put all user’s tasks there.You’ll want to add a
user_idcolumn to thetaskstable (rails g migration add_user_id_to_tasks user_id:integer) and add the following to the models –Reference: Rails Guide to ActiveRecord Associations