Skip to content

Instantly share code, notes, and snippets.

@nessamurmur
Created December 13, 2013 22:21
Show Gist options
  • Save nessamurmur/7952431 to your computer and use it in GitHub Desktop.
Save nessamurmur/7952431 to your computer and use it in GitHub Desktop.
It seems to me like it makes more since to just make use of the things rails does automagically...
class AwesomeTemplate < Template
# We don't even care about custom behavior in this template.
# We just want to be able to identify it as a different type
end
class CoolTemplate < Template
def some_method
# special case for this particular type
end
def some_custom_method
# no other template needs this method
end
end
class Template < ActiveRecord::Base
# has some fields and stuff
def some_method
# handles default behavior
end
end
@nessamurmur
Copy link
Author

With STI you would write a migration that adds a "type" fields to the templates table. Rails automatically sets the type to the subclass's name. BAM. You got types.

@nessamurmur
Copy link
Author

I'm going to flesh out both these examples more later...

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