I am trying to "soft-code" the model names in my app so I can use a
generic method call to achieve some results. Many of my modules have
the the following method:
def ModelName.get_array
# same code goes here for every module and it returns an array.
end
Is there a way to replace the model name with a variable or something
else in such a way that the method can be called in a generic way?
Something like:
I am trying to "soft-code" the model names in my app so I can use a
generic method call to achieve some results. Many of my modules have
the the following method:
def ModelName.get_array
# same code goes here for every module and it returns an array.
end
Is there a way to replace the model name with a variable or something
else in such a way that the method can be called in a generic way?
Something like:
Thanks for the tip. I have tried 'constantize' with variables and it
worked like a charm. I'll try it with my models and see how it works.
Do you know how to do something similar with variables? I have a page
with a table of 31 rows and all the field names follow the format
'field_namexx' where 'xx' is a sequence number. I have tried
constantize with regular variables but it only works with...
constants! Go figure!
Thanks Russell. I understand (or almost) what you have in mind. It
would probably be the the 'right' way to do it. I'll play with it and
see what I can come up with.