title: Sanitizing and textilizing in Model
body: <p>This is a two fold question.</p>
  
  <p>I have a RoR (3.0.7) application that accepts user input, for instance creating a news article. So far the user input was in plain XHTML as the users are trusted. However, creating posts on a website in XHTML is challenging for some users so we will try to move to textile.</p>
  
  <p>To use textile I installed RedCloth.</p>
  
  <p>Since we will not be converting the already existing news articles to textile, which I know would be the correct thing to do to have uniform data, the plan is, to use RedCloth on the content only after a given date.</p>
  
  <p>In the views I would simply have a conditional that checks for the created_at date and then call for RedCloth before outputting. However, that would mean that I had to iterate through all views and insert the conditional whenever I present that specific content. I could possibly even create a helper that would minimize the code I would have to replicate.</p>
  
  <p>Instead of doing that and keeping it DRY I decided to move the logic down in to the Model. The Model has a column called articlecontent. What I came up with is the below code, which so far seems to work:</p>
  
  <pre><code>def articlecontent
    if !self.new_record? &amp;&amp; created_at.to_datetime &gt; 'YYYY.MM.DD'.to_datetime
      articlecontent_in_textile = self[:articlecontent]
      articlecontent_in_html = RedCloth.new(articlecontent_in_textile, [:filter_html]).to_html
      return articlecontent_in_html
    else
      return self[:articlecontent]
    end
  end
  </code></pre>
  
  <p>So my questions are:</p>
  
  <p>1)
  Is this the right way to go about it? Or should I define some sort of ViewHelper?</p>
  
  <p>2)
  It seems I cannot call the sanitize helper in the Model, probably for a good reason. Is there way to call the helper in the Model?</p>
  
  <p>Thanks
  Marc</p>