CHECK FILE EXTENSION AT THE TIME OF UPLOADING
We want to check file extension before it is uploaded. The action should be executed all in the browser without using Ajax when we upload any file. Associated HTML: <%= f.file_field :file, required: true, :id => "shot_file" %> <span>(pdf,doc,docx,ppt,pptx,ods,odp,odt)</span> <div> <span class='file_ext_error text-danger'></span> </div> Please take a look at the sample JS code below: <script> $(document).on('change','#shot_file', function(){ file_name = $(this).val(); ext = file_name.split('.'); ext = ext[ext.length - 1]; valid_ext = ['pdf','msword','doc','docx','ppt','pptx','ods','odp', 'odt', 'xlsx'] if (valid_ext.indexOf(ext) >= 0) { $('.actions input').removeAttr("disabled"); $('.file_ext_error').html(''); } els