Search code examples
ruby-on-railspdf-generationpapercliprails-adminwicked-pdf

Integration with ckeditor, isnt showing the images-wicked-pdf


So, I load the images from a ckeditor, and when I render the html, it does not show, no error appears, just a blank square, instead of the image, I tried raw, html_safe, but it does not solve, the text I put is showing normally, does anyone have any idea why this happens?

a image is in

https://user-images.githubusercontent.com/26804018/31889194-ae1084e8-b7dd-11e7-85c7-1ba09d946269.png

in my view:

<h6><b>1. Objetivo:</b></h6>
<p><%= raw @pop.objective %></p>

my controller:

def show
    # redirect_to :index_pdf
    # @pop = Pop.friendly.find(params[:id])
    @pop = Pop.find(params[:id])
   pdf = render pdf: @pop.title,
           :layout => false,
           template: "pops/index_pdf.html.erb",
           locals: {:pop => @pop},
           header: { 
                      right: 'Pág. [page] de [topage].' 
                    }
                    # send_file(pdf, :filename => @pop.title+'.pdf')
                    # baixar automaticamente
                    # precisa fazer 
  end

my model:

has_attached_file :image, styles: { medium: "300x300>" }, default_url: "/images/default.png"

Solution

  • I solved by putting a helper method:

    def with_abs_path(htmlstring)
       htmlstring.to_s.gsub(/(href|src)=(['"])\/([^\"']*|[^"']*)['"]/, '\1=\2' + 'address_of_server' + '\3\2')
    end
    

    and calling in a view of my pdf:

    <%= raw with_abs_path(@pop.objective) %>
    

    the view was the same show:

    <%= raw @pop.objective %>