employees HABTM projects, projects HABTM employees. I am doing a permissions page for a selected project. I know that I can get all of the employees in the system (@employee.find(:all)) or get all the employees for the selected project. What i''m trying to do is get a list of all the employees in the system and have a check box that states if they are associated with the current project or not. Any ideas please, i''m not asking for code really just a theory of how you would possible go about it. -- Posted via http://www.ruby-forum.com/.
Project.find(id).employees On 4/13/06, James Whittaker <jmwhittaker@gmail.com> wrote:> employees HABTM projects, projects HABTM employees. > > I am doing a permissions page for a selected project. I know that I can > get all of the employees in the system (@employee.find(:all)) or get all > the employees for the selected project. > > What i''m trying to do is get a list of all the employees in the system > and have a check box that states if they are associated with the > current project or not. > > Any ideas please, i''m not asking for code really just a theory of how > you would possible go about it. > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com
Ben Reubenstein wrote:> Project.find(id).employees > > On 4/13/06, James Whittaker <jmwhittaker@gmail.com> wrote: >> Any ideas please, i''m not asking for code really just a theory of how >> you would possible go about it. >> >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Ben Reubenstein > http://www.benr75.comYes that would just get the employees that were associated with the current project. I also need the rest of the employees that are not associated. Both displayed in a list ordered by name with non repeated. The check-box would indicate if the employee was associated with the project or not. By checking the box that would then add the employee to the project. -- Posted via http://www.ruby-forum.com/.
Maybe something like this: all_employees = Employee.find_all # to find all employees in the system in an array project_employees = Project.find(id).employees # to find all employees related to this project in an array other_employees = all_employees - project_employees # a list of employees not in the project Not sure if this is what you want though :) James Whittaker wrote:> employees HABTM projects, projects HABTM employees. > > I am doing a permissions page for a selected project. I know that I can > get all of the employees in the system (@employee.find(:all)) or get all > the employees for the selected project. > > What i''m trying to do is get a list of all the employees in the system > and have a check box that states if they are associated with the > current project or not. > > Any ideas please, i''m not asking for code really just a theory of how > you would possible go about it. > > >-- Sau Sheong http://blog.saush.com http://read.saush.com http://jaccal.sourceforge.net
Chang Sau Sheong wrote:> Maybe something like this: > > all_employees = Employee.find_all # to find all employees in the system > in an array > project_employees = Project.find(id).employees # to find all employees > related to this project in an array > > other_employees = all_employees - project_employees # a list of > employees not in the project > > Not sure if this is what you want though :) > > James Whittaker wrote: >> Any ideas please, i''m not asking for code really just a theory of how >> you would possible go about it. >> >> >> > > > -- > Sau Sheong > > http://blog.saush.com > http://read.saush.com > http://jaccal.sourceforge.netNot quite what I was after though. I just wanted to be able to have a list off all the employees ordered by name ASC. Each employee would have a checkbox after there name. That check box would be checked if they had an association to the current project. If they did not then the checkbox would be unchecked. Checking the box (or unchecking ) would the add or remove the association to that project. -- Posted via http://www.ruby-forum.com/.
Just at the top of my head, I think it would be simpler if you add a method in your employee model that determines if the employee is related to the project or not: def associated_with_project?(project) if self.projects.contains? project then return true else return false end end I suppose this can be done in a cleverer way somehow but this should work :) James Whittaker wrote:> Chang Sau Sheong wrote: > >> Maybe something like this: >> >> all_employees = Employee.find_all # to find all employees in the system >> in an array >> project_employees = Project.find(id).employees # to find all employees >> related to this project in an array >> >> other_employees = all_employees - project_employees # a list of >> employees not in the project >> >> Not sure if this is what you want though :) >> >> James Whittaker wrote: >> >>> Any ideas please, i''m not asking for code really just a theory of how >>> you would possible go about it. >>> >>> >>> >>> >> -- >> Sau Sheong >> >> http://blog.saush.com >> http://read.saush.com >> http://jaccal.sourceforge.net >> > > Not quite what I was after though. I just wanted to be able to have a > list off all the employees ordered by name ASC. > > Each employee would have a checkbox after there name. That check box > would be checked if they had an association to the current project. > > If they did not then the checkbox would be unchecked. > > Checking the box (or unchecking ) would the add or remove the > association to that project. > > >-- Sau Sheong http://blog.saush.com http://read.saush.com http://jaccal.sourceforge.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/13ab4b76/attachment.html
Chang Sau Sheong wrote:> Just at the top of my head, I think it would be simpler if you add a > method in your employee model that determines if the employee is related > to the project or not: > > def associated_with_project?(project) > if self.projects.contains? project then > return true > else > return false > end > end > > I suppose this can be done in a cleverer way somehow but this should > work :) > > > James Whittaker wrote: >>> employees not in the project >>>> >> >> Each employee would have a checkbox after there name. That check box >> would be checked if they had an association to the current project. >> >> If they did not then the checkbox would be unchecked. >> >> Checking the box (or unchecking ) would the add or remove the >> association to that project. >> >> >> > > > -- > Sau Sheong > > http://blog.saush.com > http://read.saush.com > http://jaccal.sourceforge.netSounds good to me, I never thought of adding something like this into the model. All this MVC i''m still learning. However taking what you have here I get an error of: undefined method `contains?'' for Project:Class I cannot seem to find the contains? method in the API reference anywhere.Is it a ruby method? Googling contains? reveals nothing. -- Posted via http://www.ruby-forum.com/.
Found that using rubys include? method seems to provisionaly work. Just need to add the checkbox''s in and do a full test. def associated_with_project?(project) if self.projects.include? project then true else false end end -- Posted via http://www.ruby-forum.com/.