Forum: Ruby on Rails Where to put textile conversion?

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.
joevandyk (Guest)
on 2005-12-07 00:24
(Received via mailing list)
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
ksruby (Guest)
on 2005-12-07 00:36
(Received via mailing list)
There's a textilize method in TextHelper.

Kent.
rabbitblue (Guest)
on 2005-12-07 00:48
(Received via mailing list)
True, but the textilize method doesn't seem to support multiple
paragraphs.
ksruby (Guest)
on 2005-12-07 01:01
(Received via mailing list)
What do you mean by 'doesn't support'?

Kent.
joevandyk (Guest)
on 2005-12-07 01:25
(Received via mailing list)
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.
joevandyk (Guest)
on 2005-12-07 01:25
(Received via mailing list)
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.
rabbitblue (Guest)
on 2005-12-07 01:37
(Received via mailing list)
Joe you are a freaking genius. :)

- Rabbit

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

---
rails (Guest)
on 2005-12-07 02:30
(Received via mailing list)
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.
joevandyk (Guest)
on 2005-12-07 10:13
(Received via mailing list)
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.
This topic is locked and can not be replied to.