I am building a web app which has multiple projects. The general data model is such that each project has many resources such as documents, registers, etc.Something along the lines of:
class Project < ActiveRecord::Base
has_many :documents, :registers, :employments
has_many :users, :through => :employments
class User < ActiveRecord::Base
has_many :employments
has_many :projects, :through => :employments
class Document < ActiveRecord::Base
belongs_to :project
class Register < ActiveRecord::Base
belongs_to : project
The difficulty comes with routing!! Any C UD actions to projects will be done through a namespace. However, when a user is viewing a project, i want the project_id in the routes such that:
'0.0.0.0:3000/:project_id/documents/
OR
'0.0.0.0:3000/:project_id/register/1/new
I thought about something like:
match '/:project_id/:controller/:id'
I presume I am to store the project_id in a session? If i forgo these routes for something simplier such as just:
"0.0.0.0:3000/documents"
How do I then bind any CRUD actions to documents or registers to the current project?? Surely I don't have to hard wire this into every controller?
HELP!