(Rails) Various associations between otherwise unrelated entities?


(Rails) Various associations between otherwise unrelated entities?



Ok, I've got a bit of an odd situation (as if none of my others were...). Basically I have a setup where there are 4 entities:

Sites -> Buildings -> Meters -> Values 

I then have a fifth entity (Charts) that creates reports on the Values. I have a request to allow for Charts to be visually associated with any of those items in order to accommodate end users. Basically each chart can only be associated with any one entity at a time. Is there a quality "ACTS_AS" or something wild and crazy that will intuitively allow me to associate Charts with any and all entities without adding a table for each new association?

Best.




Publish to Google Tasks from rails application

1:



Interviewer: “How do you manage dependencies?”
Perhaps you want polymorphic associations..
DRYer tests with associations in factory_girl
class Chart < ActiveRecord::Base   # charts table has a chartable_id and a chartable_type column. 


Rails plugin Restful_Authentication does not work
Type is the # class name of the associated chartable: Site, Building, etc.


Rails: “Next post” and “Previous post” links in my show view, how to?
belongs_to :chartable, :polymorphic => true end class Site < ActiveRecord::Base has_one :chart, :as => :chartable end class Building < ActiveRecord::Base has_one :chart, :as => :chartable end # ...


Plugin migrations for Redmine


Which are the main things to be considered when migrating from rails 1.x to rails 2.x


95 out of 100 based on 45 user ratings 695 reviews