Ask A Question

Notifications

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!

Reply

Imma have to watch this a couple more times.

Reply

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 !

Reply

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

Reply

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

Reply

I miss something because when I do for example:

MentionNotifier.last

the error:

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

      scope_type[klass.name]
                      ^^^^^

Or MentionNotifier.new

error:

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

    @load_schema_monitor.synchronize do
                        ^^^^^^^^^^^^

someone can pointing my mistake?

Reply

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

Reply

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.

Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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