title: Rails: Undefined method error
body: <p>I just started working with rails, and I know it must be something simple I'm doing wrong, but for the life of me I can't figure it out.</p>
  
  <p>I'm trying to define a simple method in my controller for a "post" called "shorten" that will return a shortened version of whatever string I pass to it.  In my posts_controller.rb, I put the following;</p>
  
  <pre><code>def shorten(theString, length = 50)
  if theString.length &gt;= length
    shortened = theString[0, length]
  else
    theString
  end
  end
  </code></pre>
  
  <p>Trying to call it from within my view gives me an undefined method error.  I am calling it from within an instance of the post, so I assumed I didn't need self.shorten.  I went ahead and tried prepending self to the method definition anyway and it still didn't work.</p>