I am trying to develop an app to manage media files I have a folder with pictures, audio and video files.
I am using Dir.glob to list the directory in my controller and in my views I am using match with regular expressions to test if the file ends in mp3 jpg mp4 3gp wav etc ... the code I wrote seems to almost work The variable @file is passed on from the controller and here is my view.
Is this a sensible way of trying to do this?
<% if @file.match("mp4") %>
<video width="320" height="240" controls>
<source src= <%= @file %> type="video/mp4">
<% elsif @file.match("mp3") %>
<audio controls preload="auto">
<source src = <%= @file %> >
<% elsif @file.match("jpg") %>
<img src= "<%= @file %>">
<% end %>