Where to put textile conversion?


#1

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


#2

There’s a textilize method in TextHelper.

Kent.


#3

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


#4

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

Kent.


#5

On 12/6/05, Joe Van D. 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.


#6

Joe you are a freaking genius. :slight_smile:

  • Rabbit

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



#7

Goddammit, thanks. :slight_smile:

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.


#8

On 12/6/05, Ken B. 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.


#9

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.