model - Rails : Custom Callbacks at Runtime? -


I am thinking that it is possible to make a model possible in rail with the custom callback code on runtime?

I have a situation where I have many "nodes" that are making "events", and each node probably needs to run a specific callback on the event. For example, before a node can create an event, it may be necessary to call additional data on a third-party API, after creating a single event, the owner may need to send an email.

In my head, when I do "POST / node / 4 / event", then it is understandable to set something like this:

  class nodes :: event controller & Lt; ApplicationController def # ... security checks are given place and if we have @ node if @node.requers_custom_callbacks? Load the file with callback for # @ Node.id, #node4 event extensions like some # event models, finally apply the node 4 avenue extension. End End End   

This node-specific code allows my event model, and I create / test different custom node extensions. Is there anything that can be dragged in the railways? Is there another way I should see?

I've worked it like this, and it seems that less for my initial custom requirements Below, a small version of how this is connected is given below:

My controller is called a class method at the event:

  Class nodes :: EventController & Lt; ApplicationController def # ... security checks are given place and if we have @ node if @node.requers_custom_callbacks? Event.extend_for_node (node.id) end event.create end end   

The event model also includes a module for that node:

  class Event & Lt; ActiveRecord :: Base DF self.extend_for_node (node_id) contains "# node {node_id} event". Finally the end ... end   

module will include additional requirements:

  Expand modules node 20Event ActiveSupport :: Before worry is included : im_here end DEF im_here "here" end end    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -