So I am creating a web application that has the following architecture:
# Project Components resources :projects do resources :messages resources :lists do resources :tasks end end
So for each project, you can have multiple messages, as well as multiple to-do lists. Then for each to-do list, you can have multiple tasks.
However, I am ultimately want to do something like this:
# Project Components resources :projects do resources :messages resources :lists do resources :tasks do resources :messages end end end
I want to add messaging to each one of my tasks. I know this would be super easy to scaffold, but in order to not create duplicate files and database tables, what would be the best way to accomplish this?
What throws me off is that in my messages table, I have a foreign key project_id, and in order to have a message relate to a task, I would need a foreign key task_id.
create_table "messages", :force => true do |t| t.string "from" t.text "body" t.integer "project_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end
So what I want to do is have only one set of messages models, views, and controllers, but have them somehow relate to projects as well as tasks.
Does this make sense to anyone? And if so, is it possible? I'm not opposed to creating like messages-projects and messages-tasks or whatever, but if I can reduce code and files, that would be great to do.