<%= 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?
HTML5
<%= f.file_field :file, multiple: true, accept:'image/*' %>
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With