meta modeling in ActiveRecord/ Rails

22 बार देखा गया
नहीं पढ़े गए पहले मैसेज पर जाएं

mark

नहीं पढ़ी गई,
30 अक्तू॰ 2015, 12:14:12 pm30/10/15
ईमेल पाने वाला Ruby on Rails: Talk
Hi,

I am trying to create a design for user defined tables which could be stored in a database then initialized from a controller as needed. At present I am having a bit of trouble getting these metamodels into the rails env from a controller. Is there a way that I can class_eval a model that would be able to be seen for the duration of that process?

class Admin::UdtManagersController < Admin::Auth #< ApplicationController
  before_filter :initialize_meta_environment

  def index # rails complains if this isn't here
  end

    private

      def initialize_meta_environment
        @table = 'review_processes' #define this hard coded for now... later passed via param
        @model = @table.classify

        init_models
  

      end

      def init_models
        class_eval= %q{
           class #{@model} < ActiveRecord::Base

           validates_presence_of :summary_reviews
           end
          }

       ## How can I eval this model so it will become part of my application for that process?
 
      end
end

Any help is totally appreciated! Thanks in advance.

-Mark

mark

नहीं पढ़ी गई,
1 नव॰ 2015, 11:15:14 am1/11/15
ईमेल पाने वाला Ruby on Rails: Talk
Figured this out for nbow... You can do something like...


        model_class = create_arec @table do
            validates_presence_of :summary_reviews
          end

  model = Object.const_set(@table.classify, model_class)
  def create_arec(table_name, &block)
        klass = Class.new(ActiveRecord::Base){self.table_name = table_name}
        klass.class_eval &block
        klass
      end

      def create_acntl(controller_name, super_class = ApplicationController, &block)
        klass = Class.new(super_class)
        klass.class_eval &block
        klass
      end

      def compose_controller(klass, &block)
        klass.class_eval &block
      end


THis will create the objects... still have not got it doing exactly what I want to.


More later perhaps!

hope this helps someone.
--mark
सभी प्रषकों को उत्तर दें
लेखक को उत्तर दें
आगे भेजें
0 नया मैसेज