Where to put textile conversion?

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

There’s a textilize method in TextHelper.

Kent.

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

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

Kent.

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

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.


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.

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs