# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  protect_from_forgery # See ActionController::RequestForgeryProtection for details

  # Scrub sensitive parameters from your log
  # filter_parameter_logging :password
  # THE FOLLOWING METHOD IS USED TO SHORTEN TEXT AREAS FOR DISPLAY BY INDEX METHODS
  # UP TO 5 WORDS OF TEXT WILL BE PRESENT ON THE LISTING PAGES FOR TEXT AREAS, SO 
  # THE LINKS AND CONTROLS WOULD ALL BE VISIBLE.
  def short_text(txt)
    words=txt.split(" ")
    if words.length < 5
      return words.join(" ")
    end  
    first_five=""
    0.upto(4) {|w| first_five << words[w] << " "}
    first_five << "..."
    return first_five
  end  
  
  # THIS METHOD IS USED WHEREVER A PHOTO NEEDS TO BE RENDERED
  def photo
    @photo = Photo.find(params[:id])
    send_data(@photo.data,
              :filename => @photo.name,
              :type => @photo.content_type,
              :disposition => "inline")
  end 
  
end
