Display S3 images in wicked PDF - ruby-on-rails

I copied this question from https://groups.google.com/forum/#!msg/rubyonrails-talk/9Wfid1pYP7w/qqSIiW45L_8J
I have the same problem with him, please help me, thanks a lot
Hello Everyone,
I am using Wicked Pdf to generate pdf file.
In my model, i have method to generate pdf file.
I also need to show image in my pdf file from amazon s3.
Case 1:
i tried using
While i am running that method image not displaying, just a small box only appearing insteat of image.
Case 2:
i tried <%= image_tag(#image.avatar)%>
While i run this, i am getting "rake aborted!
undefined method `image_tag' for main:Object"
i googled this problem but no clear answer... any help..

First of all you need to use wicked_pdf_image_tag to show images in pdf. Try it with some local image:
<%= wicked_pdf_image_tag "some_image.jpg" %>
This should work.
Then try it with s3 image. If image doesn't show up, this mean that you using old version of wkhtmltopdf library. Download new version from http://wkhtmltopdf.org/downloads.html

Related

Cloudinary with rails won't show my picture

I am developing a Rails application and I want to upload a picture directly from my browser using Cloudinary.
I followed all steps from the Cloudinary page and ended up with a box and a question mark after I "uploaded" it, no picture at all. Any ideas what might be the problem?
I am not sure what you have used. But you should use carrierwave with cloudinary. Cloudinary having some complex way to handle display and save image if you don't use carrierwave.
But carreirwave provide simpler way to achieve uploading and display image.
Without using carrierwave
Using carrierwave in compbination
You should try the sample project and then check the differences:
https://github.com/cloudinary/cloudinary_gem/tree/master/samples/photo_album

Upload and download of files using PaperClip

I have a question that I do not really not how to answer ..
I would like my users to be able to upload and download midi files from the website.
For the upload no problem I used paperClip gem. My issue is for the download link I dont know how to do it ...
I tried a few things but the results give me just an url type ..
Could you help me ?
Thx you so much for your help!
Raphael
Solution is as simple as trying this:
<%= link_to #midi.middiz.filename, #midi.middiz.url %>
It will create an anchor tag pointing to the file to be downloaded.

Carrierwave/fog are uploading files to S3, but the app is still trying to use the local path to access images

I know this is a broad question, and I'm biting off a little more than I can chew for a first stab at a rails app, but here I am.
I tried to add an image upload/crop to a basic status app. It was working just fine uploading the images and cropping them with carrierwave, but as soon as I started using Fog to upload to S3, I ran into issues.
The image, and it's different sizes, appear to be ending up on S3 just fine, but the app is still trying to access the image as "/assets/uploads/entry/image/65/large_IMG_0035.jpg"
Locally, it just shows a broken image, but on Heroku it breaks the whole thing because
ActionView::Template::Error (uploads/entry/image/1/large_IMG_0035.jpg isn't precompiled
The heroku error makes sense to me because it shouldn't be there. I've combed through the app but don't know what's forcing this. I'll post any code anybody thinks will work? Thanks in advance!
Clarification:
Just to clarify, the images are uploading to S3 fine, the problem is how the app is trying to display the image_url
The app is using a local path in the asset pipeline, not the S3 path that it's actually uploading to.
I was having the same issue. In my Carrierwave Initializer I was setting host to s3.amazonaws.com but when I removed that line altogether urls started working.
I hope this helps you resolve your issue, I fought this for several hours!
I believe this issue is related to how you are accessing your image in your view.
If you have mounted an uploader on the field avatar in the following manner:
class User < ActiveRecord::Base
mount_uploader :avatar, AvatarUploader
end
You would access it in your ERB as follows:
<%= image_tag(#user.avatar_url) %>
I would also suggest watching the following Railscast on the topic.
http://railscasts.com/episodes/253-carrierwave-file-uploads
Re-reading issue, I bet it has to do with Carrierwave using Herkou.
Give this a glance and see if it helps.
https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku
I am not clear what exactly do you want to achieve.
But for now I have 2 ideas:
For assets host in CDN, you can take a look at this:
https://devcenter.heroku.com/articles/cdn-asset-host-rails31
If you want the images to be part of a model-relation, here's my rough idea:
Put the images path in a table column.
For further information about this you can browse carrierwave github site.(It has many docs and tutorial)

Using LightBox 2 in Ruby on Rails 3.2.3

I have done a lot of web searches to see if I could find a script where I could popup a QR code image in my Rails application. I came across Lightbox 2. I have installed the scripts and copied the CSS code in my stylesheet.
I tried to use the following code. I tried to include the path where the image is located. The page displays fine when QR Code is clicked but there is no image.
QR Code
I would like to know if I can define the path for this image using the code above or will I need to use some kind of rails statement to do this?
I have been doing searching for a couple of hours and had found several suggestions, including on Stack Overflow. However I have not seen any examples that stated that they were used in Rails applications.
Any help would be appreciated.
inside the html.erb file
<%= link_to image_tag("small_image", :size => "76x76"),'/assets/large_image.png',:rel => "lightbox"%>
image_tag is for show small thumbnail preview, make sure actual image path is /assets/image_file
if you use ordinary html tags its fine
<a href="/assets/images_file" rel="lightbox" >My Image</a>

Ruby on Rails & Prawn PDF

Im creating a PDF Document on my Website.
All works just fine, but when i try to add a Image into the PDF i get
"We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly."
So something fails with Prawn.
This is how i try
"image 'logo.png"
i tryed so many ways, all found in the internet, nothing seemed to work.
One was with the BASEDIR, how do i know where BASEDIR is?
Anyway im using OSX Server 10.6 and id be very thankfull to anwser me those questions
-Where is the Prawn Logfile?
-How does one add a Image
Thanks very much,
Greetings!
You'll need to refer to the full path to the file.
We usually refer to our images used in PDFs using the RAILS_ROOT as the starting point. So we use something like:
pdf.image "#{RAILS_ROOT}/public/images/logo-header.png"
Assuming pdf is a Prawn::Document object.

Resources