title: Validate picture upload before create object
body: <p>So i have a car class which have many photos.
  And When creating a new car i need to ensure that the user did select a picture first. 
  Here is the implementation.</p>
  
  <pre><code>class Car &lt; ActiveRecord::Base
   has_many :photos
  end
  </code></pre>
  
  <p>and class photo: </p>
  
  <pre><code>class Photo &lt; ActiveRecord::Base
  belongs_to :car
  
  has_attached_file :image, styles: { medium: "300x300&gt;", thumb: "100x100&gt;" }
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
  end
  </code></pre>
  
  <p>Here is a part of the car form: </p>
  
  <pre><code>  &lt;%= form_for @car, :html =&gt; { multipart: true } do |f| %&gt;
  
              &lt;div class="col-xs-6"&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label&gt;Modele&lt;/label&gt;
                      &lt;%= f.text_field :modele, placeholder: "Modele", class: "form-control" %&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
                  &lt;div class="row"&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;div class="form-group"&gt;                            
                          &lt;span class="btn btn-default btn-file"&gt;
                              &lt;i class="fa fa-cloud-upload fa-lg"&gt;&lt;/i&gt; Upload Photos 
                              &lt;%= file_field_tag "images[]", type: :file, multiple: true %&gt;
                          &lt;/span&gt;
                      &lt;/div&gt;      
                  &lt;/div&gt;
              &lt;/div&gt;
     &lt;% end %&gt;
  </code></pre>