title: What is the def to_s function?
body: <p>I'm going through the "Tags" section of the <a href="http://tutorials.jumpstartlab.com/projects/blogger.html#i3%3a-tagging" rel="nofollow">Blogger</a> tutorial and am a bit confused on one part: the def to_s function (in tag.rb); why it's required and how it's included.</p>
  
  <p>I've included some relevant parts of relevant files for context.</p>
  
  <p><em><strong>MODELS</em></strong></p>
  
  <p><strong>article.rb</strong></p>
  
  <pre><code>class Article &lt; ActiveRecord::Base
    attr_accessible :tag_list
    has_many :taggings
    has_many :tags, through: :taggings
  
    def tag_list
      return self.tags.collect do |tag|
        tag.name
      end.join(", ")
    end
  
    def tag_list=(tags_string)
      self.taggings.destroy_all
  
        tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq
  
        tag_names.each do |tag_name|
          tag = Tag.find_or_create_by_name(tag_name)
          tagging = self.taggings.new
          tagging.tag_id = tag.id
        end
      end
    end
  </code></pre>
  
  <p><strong>tag.rb</strong></p>
  
  <pre><code>class Tag &lt; ActiveRecord::Base
    has_many :taggings
    has_many :articles, through: :taggings
  
    def to_s
      name
    end
  end
  </code></pre>
  
  <p><b>tagging.rb</b></p>
  
  <pre><code>class Tagging &lt; ActiveRecord::Base
    belongs_to :tag
    belongs_to :article
  end
  </code></pre>
  
  <p><em><strong>CONTROLLERS</em></strong></p>
  
  <p><b>tags_controller.rb</b></p>
  
  <pre><code>class TagsController &lt; ApplicationController
  
    def index
      @tags = Tag.all
    end
  
    def show
      @tag = Tag.find(params[:id])
    end
  
    def destroy
      @tag = Tag.find(params[:id]).destroy
      redirect_to :back
    end
  end
  </code></pre>
  
  <p><em><strong>HELPERS</em></strong></p>
  
  <p><b>articles_helper.rb</b></p>
  
  <pre><code>module ArticlesHelper
  
    def tag_links(tags)
      links = tags.collect{|tag| link_to tag.name, tag_path(tag)}
      return links.join(", ").html_safe
    end
  end
  </code></pre>
  
  <p><em><strong>VIEWS</em></strong></p>
  
  <p><b>new.html.erb</b></p>
  
  <pre><code>&lt;%= form_for(@article, html: {multipart: true}) do |f| %&gt;
    &lt;p&gt;
      &lt;%= f.label :tag_list %&gt;
      &lt;%= f.text_field :tag_list %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.submit %&gt;
    &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><b>show.html.erb</b>
      <p>Tags: <code>&lt;%= tag_links(@article.tags) %&gt;</code></p></p>