maletor
maletor

Reputation: 7122

Render html from a template with rendering a view

I am sending a fax through a Fax API module I built.

The plan is to mix it into my Fax model and just call self.send_fax. The Fax table itself will have a fax_number column which it expects along with a recipeint name. In order to send this.

One more thing it needs to expect is raw_html. The way I'm thinking about doig this would be to create an attr_accessor for it and when the Fax object is created inject it with all the HTML that it needs.

How can I call render from the controller without actually rendering a view, just processing it and adding the result to the column?

Does this method of solving the problem make the most sense? Can you think of a better way to do it?

Upvotes: 0

Views: 60

Answers (1)

M. Cypher
M. Cypher

Reputation: 7066

What you want to use is the render_to_string method. It works just like render in your controller, but it returns the rendered view HTML as a string, instead of sending it in the response body.

http://api.rubyonrails.org/classes/AbstractController/Rendering.html#method-i-render_to_string

Upvotes: 2

Related Questions