hitsvilleusa / acts_as_polymorphic Goto Github PK
View Code? Open in Web Editor NEWCreates an acts_as_<polymorphic>.rb which can be reused when working with polymorphic associations.
License: MIT License
Creates an acts_as_<polymorphic>.rb which can be reused when working with polymorphic associations.
License: MIT License
ActsAsPolymorphic ================= TODO: Add documentation. This is important because the introduction of a polymorphic association means that more than one model is going to have a 'has_many :as'. Now, while this may not seem too repetitive to add to a few different classes, it easily can be. This is especially true if you start caring about the :dependent relationship. Or, if you add new methods based on the association. Example ======= TODO: This example isn't great because it illustrates something that is common with a many-to-many class Tag < ActiveRecord::Base belongs_to :taggable, :polymorphic => true end class Movie < ActiveRecord::Base acts_as_taggable end class Photo < ActiveRecord::Base acts_as_taggable end class Song < ActiveRecord::Base acts_as_taggable end All you need to do is run this: script/generate acts_as_polyorphic taggable tags or script/generate acts_as_polyorphic taggable tags tag destroy which generates (in the former case) module ActiveRecord module Acts module Taggable def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_taggable class_eval do include ActiveRecord::Acts::Taggable::InstanceMethods has_many :tags, :class_name => "Tag", :as => :taggable, :dependent => :nullify end end end module InstanceMethods # Add instance methods here for the taggables end end end end ActiveRecord::Base.class_eval { include ActiveRecord::Acts::Taggable } Copyright (c) 2010 Chris Morris, released under the MIT license
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.