Ask A Question


You’re not receiving notifications from this thread.

Dynamic Single Table Inheritance with Rails Discussion

This was really fun. I wanted an easy way to introduce helpers to Notifications so by exposing them also as STI models, we could make them easily accessible with separate helper methods for each Notifier type. Super cool how flexible Ruby is for allowing these types of solutions!


Imma have to watch this a couple more times.


I think I will use this to rewrite my event driven system. STI + to be able to have access to the aggregate context is a must ! Thanks Chris !


Really cool! How about the tests here. how can you ensure that a model will fail if it have not defined the required methods?


You can either check the class with is_a? or check methods if with respond_to?


I miss something because when I do for example:


the error:

/scoping.rb:127:in value_for': undefined methodname' for nil:NilClass (NoMethodError)




/model_schema.rb:560:in load_schema': undefined methodsynchronize' for nil:NilClass (NoMethodError)

    @load_schema_monitor.synchronize do

someone can pointing my mistake?


Hello Benoit, I'm not sure but with this I have solved this problem
def self.inherited(notifier)
notifier.const_set :Notification,


To answer your question Chris, would love more meta programming content. Always a topic I have to study a few times, haven't seen it yet but a series that helps people level up their meta programming game (starting from basics) would be great. Thanks for a great session here.


Maybe we'll start a new series on metaprogramming. 👍

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.