# Where to put textile conversion?

**URL:** <https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579>\
**Category:** Rails\
**Created:** [December 6, 2005, 11:24pm UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579 "2005-12-06T23:24:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 6, 2005, 11:24pm UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/1 "2005-12-06T23:24:26Z")

</div>

The appropriate place to use Textile is in the controller, right?

i.e.

class ArticleController \< AC  
def show  
# stuff  
@article.body = RedCloth.new(@article.body).to\_html  
end  
end

Or should it go in the model?

Joe

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 6, 2005, 11:36pm UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/2 "2005-12-06T23:36:43Z")

</div>

There’s a textilize method in TextHelper.

Kent.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 6, 2005, 11:48pm UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/3 "2005-12-06T23:48:55Z")

</div>

True, but the textilize method doesn’t seem to support multiple  
paragraphs.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 12:01am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/4 "2005-12-07T00:01:05Z")

</div>

What do you mean by ‘doesn’t support’?

Kent.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 12:25am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/5 "2005-12-07T00:25:32Z")

</div>

On 12/6/05, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Or should it go in the model?

Are there any compelling arguments about why it shouldn’t go in the  
model?

i.e.

class Article \< AR  
def body  
read\_attribute(:body).to\_textile # See my other post  
end  
end

That’s what I’m doing now, anyways.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 12:37am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/6 "2005-12-07T00:37:45Z")

</div>

Joe you are a freaking genius. 🙂

- Rabbit

PS: And no, I see no compelling arguments why that shouldn’t go into the  
model.

* * *

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 12:25am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/7 "2005-12-07T00:25:31Z")

</div>

Goddammit, thanks. 🙂

I dunno if this is clever or not, but I extended the String class:

class String  
def to\_textile  
RedCloth.new(self).to\_html  
end  
end

And then whenever I need to convert a string to textile, it’s just  
“this is the string”.to\_textile.

But it’s good to know about that stuff.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 9:13am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/8 "2005-12-07T09:13:38Z")

</div>

On 12/6/05, Ken B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If you are putting it into the model, make it something like:
> 
> def body\_html  
> read\_attribute(:body).to\_textile  
> end
> 
> That way you can access the unproccessed text for editing.

That’s not necessary. Dunno why though.

---

<div class="post-metadata">

**Author:** ![joevandyk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c0e974/32.png) [@joevandyk](https://www.ruby-forum.com/u/joevandyk)\
**Post date:** [December 7, 2005, 1:30am UTC](https://www.ruby-forum.com/t/where-to-put-textile-conversion/52579/9 "2005-12-07T01:30:31Z")

</div>

If you are putting it into the model, make it something like:

def body\_html  
read\_attribute(:body).to\_textile  
end

That way you can access the unproccessed text for editing.
