# How do I format text before saving it?

**URL:** <https://www.ruby-forum.com/t/how-do-i-format-text-before-saving-it/56320>\
**Category:** Rails\
**Created:** [March 30, 2006, 6:24am UTC](https://www.ruby-forum.com/t/how-do-i-format-text-before-saving-it/56320 "2006-03-30T06:24:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eleo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea5d25/32.png) [@eleo](https://www.ruby-forum.com/u/eleo)\
**Post date:** [March 30, 2006, 6:24am UTC](https://www.ruby-forum.com/t/how-do-i-format-text-before-saving-it/56320/1 "2006-03-30T06:24:24Z")

</div>

I tried to use a before\_save and use simple\_format, it returns and  
undefined method error. Can I even use these methods within a model? I  
tried to use auto\_link and it failed too. What am I doing wrong?

Furthermore, would it be recommended I format text before saving it to  
the database? Advantages or disadvantages?

---

<div class="post-metadata">

**Author:** ![eleo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea5d25/32.png) [@eleo](https://www.ruby-forum.com/u/eleo)\
**Post date:** [March 30, 2006, 1:04pm UTC](https://www.ruby-forum.com/t/how-do-i-format-text-before-saving-it/56320/2 "2006-03-30T13:04:06Z")

</div>

Eleo wrote:

> I tried to use a before\_save and use simple\_format, it returns and  
> undefined method error. Can I even use these methods within a model? I  
> tried to use auto\_link and it failed too. What am I doing wrong?
> 
> Furthermore, would it be recommended I format text before saving it to  
> the database? Advantages or disadvantages?

I guess you could but you need to point to the helper in your model:  
helper :text\_helper

but maybe it’s better to format in the view where you want to display  
the given text, if for instance you would like to be able to edit it in  
a simple text field it might be confusing for the user to see tags  
there.

–  
Agnieszka

---

<div class="post-metadata">

**Author:** ![eleo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea5d25/32.png) [@eleo](https://www.ruby-forum.com/u/eleo)\
**Post date:** [March 30, 2006, 2:32pm UTC](https://www.ruby-forum.com/t/how-do-i-format-text-before-saving-it/56320/3 "2006-03-30T14:32:39Z")

</div>

Assuming that your text is only going to be interpreted by your  
application’s view, where you can control the interpretation, it seems  
more efficient to save the unformatted text to the database.

If another application is accessing the database or using the text, and  
you don’t have control over how that app formats the text, then it might  
make sense to pre-format it, but otherwise, why not just call  
“simple\_format” in your view before you display the text?

Jeff

Agnieszka F. wrote:

> Eleo wrote:
> 
> > I tried to use a before\_save and use simple\_format, it returns and  
> > undefined method error. Can I even use these methods within a model? I  
> > tried to use auto\_link and it failed too. What am I doing wrong?
> > 
> > Furthermore, would it be recommended I format text before saving it to  
> > the database? Advantages or disadvantages?
> 
> I guess you could but you need to point to the helper in your model:  
> helper :text\_helper
> 
> but maybe it’s better to format in the view where you want to display  
> the given text, if for instance you would like to be able to edit it in  
> a simple text field it might be confusing for the user to see tags  
> there.
> 
> –  
> Agnieszka
