I have a controller that I want to refactor. This controller basically renders a formatted XML document.
The controller does 4 main things.
- It get records from a DB
- It reads a static xml file from rails_root/config
- It iterates through DB records and gsubs the XML doc using the DB data
- It renders the XML document as :text
My question is:
Where is the correct place for 2/3 to happen within in the Rails framework? It seems to me that they shouldn’t be in the controller.
I’m on Rails 2.3
Cheers
I don’t know what best practice is, but in my case I’d do 1, 2, and 3 in one class method in the model. I’d create a model method that takes in the name of the base XML file.
So I’d do something like this… (CAVEAT: I’m not 100% sure about this being syntactically correct, I’m still kind of new to Rails)