Rendering advice for has_and_belongs_to_many relationship?


#1

I am working on a time tracking app; you have users and projects, and
users can be included as part of a project.

This shows itself in the UI of the site in two ways. The first, that
users can only choose to record time against projects they are a part
of, was pretty simple to add.

However the second change to the site, that administrators creating
and editing projects can choose which users have access, seems like I’m
writing too much code. On the project add/edit form, I want to have a
list of all users with checkboxes to set who has access. I think the
thing that is getting me is that the has_and_belongs_to_many methods do
not allow me to get a list of say every project and a boolean showing
if there is a relationship, or use such a list to update the database
records.

Data model subset:
CREATE TABLE projects (“id” INTEGER PRIMARY KEY NOT NULL, “name”
varchar(255));
CREATE TABLE projects_users (“id” INTEGER PRIMARY KEY NOT NULL,
“user_id” integer NOT NULL, “project_id” integer NOT NULL);
CREATE TABLE users (“id” INTEGER PRIMARY KEY NOT NULL, “name”
varchar(255), “hashed_password” varchar(255), “salt” varchar(255),
“admin” boolean DEFAULT 0 NOT NULL);

-DW