I need help with the development of the rails that I am working on using rails 3. This application was provided to me a few months ago immediately after its creation, and since then I have loved Ruby very much.
I have a set of projects that can have resources assigned through a command table.
The team record has a start date and an end date (that is, when the resource was assigned and removed from the project).
If a user has been assigned and disconnected from the project, and at a later date they will be assigned back to the project, instead of writing the end date, I want to create a new entry in the Commands table so that I can track the dates when the resource was assigned specific project.
So my question is: is it possible to have multiple entries in: has_many through an association?
Here are my associations:
class Resource < ActiveRecord::Base has_many :teams has_many :projects, :through => :teams end class Project < ActiveRecord::Base has_many :teams has_many :resources, :through => :teams end class Team < ActiveRecord::Base belongs_to :project belongs_to :resource end
I also have the following function in Project.rb:
after_save :update_team_and_job private def update_team_and_job # self.member_ids is the selected resource ids for a project if self.member_ids.blank? self.teams.each do |team| unless team.deassociated team.deassociated = Week.current.id + 1 team.save end end else self.teams.each do |team| #assigning/re-assigning a resource if self.member_ids.include?(team.resource_id.to_s) if team.deassociated != nil team.deassociated = nil team.save end else #de-assigning a resource if team.deassociated == nil team.deassociated = Week.current.id + 1 team.save end end end y = self.member_ids - self.resource_ids self.resource_ids = self.resource_ids.concat(y) self.member_ids = nil end end end
source share