views:

28

answers:

1

I'm doing some refactoring on a piece of code I have, and am thinking of moving some stuff from the model into helper methods.

Nothing major, but my model does some screen-scrapping, and I need to treat (and filter) some of the strings returned, so they are passed back to the controller nicely formatted.

I've been using helper methods with my view already.

My question is, is it a good practice to use helper methods with the model, or should I simply add my string cleaning methods in the model itself?

Thanks in advance

A: 

Since you don't give an example, it's hard to be specific, but in general, I like to put re-usable functionality in models, especially if it relates to the model in question.

A generic example off the top of my head:

def name
  first_name + " " + last_name
end

Instead of having the equivalent in a helper method. I mean, if you already have a model dedicated to screen-scraping, it makes sense that it would have a bunch of methods in it (maybe extracted into modules/libraries/plugins where appropriate) that did the business involved in screen scraping.

I have seen examples of people using helper methods with models, but I try to avoid that in general. That said, there are exceptions to every rule. :)

dpb
That's the thing, I don't have a dedicated model for screen scrapping. Would you recommend doing so?
Marcos Placona
Makes sense to me. If that is part of your application, and it is storing stuff that resulted from the screen scrape, it makes sense to me to have a model for it.
dpb