Ruby on Rails Monday, April 18, 2016

thanks

On Monday, April 18, 2016 at 2:50:08 AM UTC-4, Colin Law wrote:
On 17 April 2016 at 23:26, fugee ohu <fuge...@gmail.com> wrote:
> lI'm trying to develop an app to manage media files I have a folder with
> pictures, audio and video files I'm using Dir.glob to list the directory in
> my controller and in my views i'm 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's 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">
>  </video>
> <% elsif @file.match("mp3") %>
>  <audio controls preload="auto">
>   <source src = <%= @file %> >
>  </audio>
> <% elsif @file.match("jpg") %>
>  <img src= "<%= @file %>">
> <% end %>

Do you have a File model?  If so then provide either instance or class
methods to do the file type testing rather than having code for them
in the view.  If you don't have a File model then create one (not
ActiveRecord based) to manage the logic.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1b9bb58a-ed44-4995-8396-4da99f6818f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment