Here's what I have today: I output a list of @users
What I need to do is output a list of users and say if they are assigned to the current project.
I could loop through each user and check in the database, but that would be a lot of data base hits, an additional 10 hits for displaying 10 users.
My question to you, is there a smart, more efficient, rails way to do this? Ideas: Perhaps I load a list of all of a project's current users, and check against that array when outputting through the user's loop? Or maybe some other method?
Interested in hear your suggestions and if you don't mind a small code snippet to get me started.
Thank you!
UPDATE - adding models
User model
belongs_to :instance
has_many :permissions
has_many :projects, :through => :permissions
Permissions Model:
belongs_to :user
belongs_to :project
belongs_to :role
Project Model:
has_many :permissions
has_many :users, :through => :permissions
The query I'm using currently is:
@users = find(:all, :joins => :instance, :select => 'users.*, instances.domain', :conditions => ['fname LIKE ? or lname LIKE ?', "%#{search}%", "%#{search}%"])
What I want to know is, for the user being displayed. Are they currently a member of the project_id in the URL? Or if not, show an ADD Member button.