title: Rails how to validate file format?
body: <p>How do I validate my file fields for the correct format?</p>
  
  <p>I want the image field to validate that it is a .png, .jpg, .jpeg.</p>
  
  <p>And the flv that it has the ending .flv</p>
  
  <p>And the quicktime that it have the ending .mov</p>
  
  <p>And how do I create error messages to tell that the field is not valid.</p>
  
  <p>My simple_form_for:</p>
  
  <pre><code>&lt;%= f.input :name, :label =&gt; 'Navn', :required =&gt; true %&gt;&lt;br /&gt;
  &lt;%= f.label :tekst %&gt;&lt;br /&gt;
  &lt;%= f.text_area :text, :label =&gt; 'Text', :size =&gt; '12x12' %&gt;&lt;br /&gt;
  &lt;%= f.label "Upload billede - kræves" %&gt;&lt;br /&gt;
  &lt;%= f.input :image, :label =&gt; '', :required =&gt; true %&gt;&lt;br /&gt;
  &lt;%= f.label "Upload flv - kræves" %&gt;&lt;br /&gt;
  &lt;%= f.input :flv, :label =&gt; '', :required =&gt; true %&gt;&lt;br /&gt;
  &lt;%= f.label "Upload Quicktime - kræves"  %&gt;&lt;br /&gt;
  &lt;%= f.input :quicktime, :label =&gt; '', :required =&gt; true %&gt;&lt;br /&gt;
  &lt;%= f.button :submit, :value =&gt; 'Create movie' %&gt;
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>I have figure out how to validate the .mov and .flv fields:</p>
  
  <pre><code>validates_format_of :flv, 
  :with =&gt; %r{\.flv$}i, :message =&gt; "file must be in .flv format"
  
  validates_format_of :mov, 
  :with =&gt; %r{\.mov$}i, :message =&gt; "file must be in .mov format"
  </code></pre>
  
  <p>I just don´t have found a solution to validate the image. </p>
  
  <p>My controller:</p>
  
  <pre><code>def savenew
      @photographer = Photographer.new(params[:photographer]) 
      @photographer.sort_order = Photographer.count + 1
  
      if @photographer.save   
        redirect_to :action =&gt; 'list', :id =&gt; params[:id]
        flash[:notice] = "Movie #{@photographer.name} is created"
      else    
        render 'create', :id =&gt; params[:id]             
      end                                 
  end         
  </code></pre>