0

My current project requires me to assemble a .zip file containing HTML and text-only templates for a user to download, for importing into an email marketing program.

I've inherited this project, and currently the code uses a "fake" model (that is a model that does not directly correlate to a database table), in which it stores the entire template in a string, using dynamic variables to populate certain areas. The "fake" model then has a method for creating a zip file.

It seems to me that there has to be a better way to do this. I was wondering if there was a way to move the template into a .erb/haml file, and then write a method that would populate the file in preparation for being zipped up? Basically, is there a way to render an HTML and text file, without actually having to display them?

Thanks for any help.

2
  • "fake" model or controller? Normally the controller is responsible for the rendering and not the model. Commented May 5, 2010 at 19:16
  • It's a class located in the models folder, but it isn't associated with a database object. Instead, it requires the the ID of an actual model to be passed to it when the class is called. Commented May 5, 2010 at 19:43

2 Answers 2

1

Just write the action and view to render the html and text as normal then use the render_to_string method to assign the content to strings

http://apidock.com/rails/ActionController/Base/render_to_string

Then you can run the Model method (hopefully a Class method) to create the zip file using the content you now have in instance variables

Sign up to request clarification or add additional context in comments.

Comments

0

Please have a look at the cells plugin.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.