Forum: Ruby on Rails How do I format text before saving it?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F9baac8d679b8728c0b8023e34c61666?d=identicon&s=25 Eleo (Guest)
on 2006-03-30 06:24
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?
5b132632f47e8c7e2a83157cef4649c8?d=identicon&s=25 Agnieszka Figiel (agnessa)
on 2006-03-30 13:04
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
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-03-30 14:32
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 Figiel 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
This topic is locked and can not be replied to.