I have a single table inheritance setting where I have one controller (I felt that multiple instances were duplicating). However, for some methods I would like to subclass models. I decided that I have a browser that will send a parameter with which I would write a case argument. Sort of:
case @model[:type] when "A" @results = Subclass1.search(params[:term]) when "B" @results = Subclass2.search(params[:term]) ... end
Alternatively, although I learned that Ruby, in all of this, cheating can create a model from a string. Sort of:
@results = params[:model].constantize.search(params[:term])
My question is: is this a bad practice? I can imagine that someone sneaky can create a request that forces me to form an arbitrary internal object. But I could confirm that the object is a subclass of what I want.
source share