[Rails] Html to plain text


I need to extract some text from a model in order to publish it in a CSV file. My problem was that one field's content is in pure html, like:

& quot; name & quot;=& gt;
[& quot;TommasoTorti& quot;, & quot;Tommaso& quot;]
; but in my csv file i need the text in a plain format.
One way is to unescape the html in the model:


def to_csv
[... , CGI.unescapeHTML(self.field) ].join("\t")
end


and insert the 'raw' command inside the view:

<%= raw my_model.to_csv %>


(The controller's code:


@models = MyModel.all
response.headers["Content-Type"] = "text/csv; charset=UTF-8; header=present"
response.headers["Content-Disposition"] = "attachment; filename=my_models.csv"
render :layout => false

)

Nessun commento: