Skip to content

Instantly share code, notes, and snippets.

@sandheepg
Last active March 8, 2017 07:46
Show Gist options
  • Select an option

  • Save sandheepg/92ffd6cc411df76e2105c24acb96faf4 to your computer and use it in GitHub Desktop.

Select an option

Save sandheepg/92ffd6cc411df76e2105c24acb96faf4 to your computer and use it in GitHub Desktop.
Abstract classes in rails
class AbstractModel < ActiveRecord::Base  
  self.abstract_class = true
end

class Foo < AbstractModel
end

class Bar < AbstractModel
end

Foo and Bar both inherit properties and methods of the Abstract Model while being in separate tables of their own.

The whole purpose of an abstract model is to be inherited by other real models, it has no table. Abstract models are the models which cannot have objects ( cannot be instantiated ) and hence they don’t have associated table as well.

eg. ActiveRecord::Base. Abstract Model is similar to ActiveRecord::Base with some extra behavior.

Reference here here and here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment