mongodb - how to display uploaded pdf/text_files/videos using mongoid-paperclip -


i using mongoid-paperclip gem upload files. able display images have uploaded. how display pdfs/videos.

please me solution.

this image model.

class image   has_mongoid_attached_file :logo   validates_attachment :logo, :content_type => [ "application/pdf"]   validates_attachment_content_type :logo, :content_type => ["image/jpg", "image/jpeg", "image/png"]    field :logo end 

view file:

<% @images.each |image| %> <%=  image_tag(image.logo.url(:original)) %> <% end %> 

thanks in advance.

replace

  validates_attachment :logo, :content_type => [ "application/pdf"]   validates_attachment_content_type :logo, :content_type => ["image/jpg", "image/jpeg", "image/png"] 

with

  validates_attachment_content_type :logo, :content_type => ["image/jpg", "image/jpeg", "image/png", "application/pdf"] 

no need validate separately validating same logo field.

i assuming have installed ghostscript(brew install gs if using mac). thats requirement pdf upload using paperclip. if not, install first , restart rails server.

in view, add following code:

<% @images.each |image| %> <% if image.logo.image_content_type == 'application/pdf' %>    <iframe src=<%= image.logo.url(:original) %> frameborder="0"></iframe> <% else %>     <%=  image_tag(image.logo.url(:original)) %> <% end %> <% end %> 

iframe inline frame mechanism used embed document within current html. above code tested using environment: ruby 2.1.0, rails 4.0.2, mac os mavericks, paperclip 3.5.3

edit

checkout paperclip-ffmpeg gem used adding video handling paperclip via ffmpeg. make sure ffmpeg installed on machine.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -