The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

alternating rendered partial base on model type

So i'm using Single Table inheritance for a Entry model. There is Text and File. Is there a best practice for outputting a partial and alternating between the two based on the 'type' column (WITHOUT using the type column as i've read this is bad practice).

your brain reacts in the same way whether you are
looking at something or thinking about it...

Apparently is_a? is inheritance aware so, if I ever have to create a subclass of type_a OR type_b, those will be picked up as well... my first method would only pick up the class mentioned and NOT any subclasses.

your brain reacts in the same way whether you are
looking at something or thinking about it...

And if you were serious about moving the decision out of the view, the first thing is to move the "what kind" decision into the model. basically, you'd create either a boolean or some similar indicator method for the model then use that flag in the controller to dictate which view you're going to render.

Remember, you're going to want to keep most of your logic in the model, so complicated decision trees go there, with simple operations in the controller.

I should have been clearer. When I said the "what kind" decision belonged in the model, I meant "what kind of record am I?" decision. A simple boolean, perhaps called "is_text?" or "is_html?" is added to the model, and the function returns T/F depending on the result of the decision. The controller should not know what making this decision involves, it should only know what the result of the decision is.

Now the controller looks at that simple boolean and renders the correct template.

If you expand the choices beyond binary (html/text to, say, html/text/xml/csv or whatever) then you'd probably dispense with the binary and create a simple variable you can use in a case statement.