How to create an ActiveRecord dynamic creation class during runtime? (ruby)

I am trying metaprogramming and want to dynamically create a class that inherits from ActiveRecord.

For example, I can do this:

< p>

Object.const_set("Orders", Class.new {def blah() 42 end })

So now I can:

o = Orders.new
o.blah #<== 42

But when I try:

Object. const_set("Orders", Class.new 

Give me a syntax error and

 Object.const_set("Orders", Class.new {def blah() 42 end} 

I won’t complain until I try to instantiate the Orders class

Is there a tip?

Thank you.

try this:

SomeClass = Class.new(ActiveRecord::Base) do
.... #some behaviour
end

I am trying metaprogramming and want to dynamically create a class that inherits from ActiveRecord.

For example, I can do this:

Object.const_set("Orders", Class.new {def blah() 42 end })

So now I can:

o = Orders .new
o.blah #<== 42

But when I try:

Object.const_set("Orders", Class. new 

Give me a syntax error and

Object.const_set("Orders", Class.new {def blah() 42 end} 

I won’t complain until I try to instantiate the Orders class

Are there any tips?

Thank you.

Try this:

SomeClass = Class.new(ActiveRecord::Base) do
.... #some behaviour
end

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3359 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.