ruby-on-railsrubyerbwicked-pdf

image_tag not returning image using url in service


module FileService
  class LetterGenerator
    def initialize(user)
      @user = user
    end

    def process
      WickedPdf.new.pdf_from_string(
        ApplicationController.new.render_to_string(
          template: 'services/main.pdf.erb',
          locals: { user: user}
        )
        margin: { top: 10, bottom: 20 }
      )
    end

    private

    attr_reader :user
  end
end

main.pdf.erb

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<div class="letter">
  <div class='header'>
    <div class='header-right'>
      <b>Letter</b>
    </div>
    <div class='logo'>
      <% if @user.client %>
        <%= image_tag Setting.take.logo.url, size: "100x50" %>
      <% else %>
        <%= image_tag wicked_pdf_asset_base64('mailer/logo.png') %>
      <% end %>
    </div>
  </div>
</div>

The image is present in Settings table but doest show in pdf.erb file. I thing this issue is how to use image_tag to display image in service. Not 100% sure . Please help me resolve it

Setting.take.logo.url is

/uploads/setting/logo/1/America_1.png

Solution

  • <img src="<%= Settings.default.host + Setting.take.logo.url %>">

    This worked for me