How to limit only images to be uploaded through file_field tag?

forms, ruby, ruby-on-rails

Solution

You can use paperclip gem to manage file attachments. It has `validates_attachment` validator which would be helpful.

validates_attachment :avatar, :presence => true,
  :content_type => { :content_type => "image/jpg" },
  :size => { :in => 0..10.kilobytes }

Problem

``` <%= form_for @model_name, :url => {:controller => 'controller_name', :action => 'index'},:html => {:multipart => true},:validate => true do |f| %> <%= file_field 'upload', 'datafile'%> <% end %> ``` I have this form. I want to upload only images through this upload. How to do this?

Original source