title: rails - instance model include module on variable condition
body: <p>I need to know if I can include a module to an instantiated model.</p>
  
  <p>What works today : </p>
  
  <p><strong>in the controller</strong></p>
  
  <pre><code>@m = MyModel.create(params)
  </code></pre>
  
  <p><strong>in the model</strong></p>
  
  <pre><code>class Doc &lt; ActiveRecord::Base
  
     after_save :set_include
  
     def set_include
       if bool
         self.class.send(:include, Module1)
       else
         self.class.send(:include, Module2)
       end
     end
  
  end
  </code></pre>
  
  <p>and this works, but I'm afraid that <code>self.class</code> actually include the module for the class model an not the <strong>instantiated model</strong></p>
  
  <p>In this case, this will work.
  The module methods are call after the object is saved.</p>
  
  <p>But in many case, the controller will call some modules methods.</p>
  
  <p><strong>I thought of</strong>  called the method <code>set_include</code> (up there) in a <code>before_action</code> of the controller.
  But I really thinks that is not a good idea...</p>
  
  <p>Any idea how I can really do that with in a good way ?</p>
  
  <p>thanks !</p>