Everthing works perfect on my local, but on production(Heroku) some images in the generated pdf are not showing:
<img alt="Bg_pdf" id="background" src="file:////app/app/assets/images/bg_pdf.jpg">
<img alt="Bg_pdf2" id="background2" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Bg_pdf2" id="background3" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Bg_pdf2" id="background4" src="file:////app/app/assets/images/bg_pdf2.jpg">
<img alt="Step_4" id="pic3" src="file:////app/app/assets/images/steps/raka/right/step_4.jpg" style="margin-top: 20px;">
The #pic3 does not appear, but all the other images above appear.
Why does pic3 not appear in the generated pdf? Is there because there is some sort of maximum amount of images allowed?
In my gem file:
gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
gem 'wkhtmltopdf-heroku'
And I am using the helper method:
<%= wicked_pdf_image_tag("steps/#{session[:product]}/#{session[:sving]}/step_4.jpg", :id => 'pic3', :style => 'margin-top: 20px;') %>
Some trouble with .jpg, jpeg images, used .PNG images instead and it works well.
Related
I am having very difficulties to display images on production. The images are showing perfectly fine in local development but once it goes to production, it displays nothing. There are a few lines of code I have tried
System.pdf.erb
#1
<img src="'<%= url_for(system.last.image)%>"> <br><br><hr>
#2
<%= wicked_pdf_image_tag
system.last.image.service_url.gsub("https", "http") %>
#3
<%= wicked_pdf_image_tag
system.last.image.service_url.gsub("https", "http") %>
#4
<img src="<%= system.last.image.variant(resize:
"590").processed.service_url %>">
Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
None of above works. Please help.
Currently I do this for my website
image_tag("logo.png")
This results
<img src="/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png" alt="Logo" />
This works just fine for me. But sometimes I just need the source part of the image i.e I just need this part /assets/logo-c9dc9867ad75fdidmjdoehdo53di.png. How can I get it?
If your images are in app/assets/images, then use asset_path
<%= asset_path("logo.png") %>
# => "/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png"
If your images are in public/assets, then use image_path
<%= image_path("logo.png") %>
# => "/assets/logo-c9dc9867ad75fdidmjdoehdo53di.png"
Windows 8.1
Rails 4.1
Ruby 2.0
I have the CarrierWave
class AvatarUploader < CarrierWave::Uploader::Base
Cw_image_folder = '/agents/uploads/cw/'
def store_dir
"#{Cw_image_folder}#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
This is working for uploads and images as well as their various versions (thumb, small and medium) are stored in the defined store_dir.
The problem is that when I try to use the images, like this:
<img class="media-object" src="<%= #agent.avatar.current_path(:medium) if #agent.avatar? %>" alt="Image Not Found">
or this:
<img class="media-object" src="<%= #agent.avatar.url(:medium) if #agent.avatar? %>" alt="Image Not Found">
The image is not displayed. Searching through the logs, here's what I find:
Started GET "/images/C%3A/agents/uploads/cw/agent/avatar/36/thumb_img_1984.jpg" for 127.0.0.1 at 2014-06-09 03:43:13 -0700
Why is the /images/C%3A added to the beginning?
To store correct path in db, use this
<%= image_tag #agent.avatar.url if #agent.avatar? %>
I've got a rake task which uploads images I've cached from an API to my S3 bucket. In my view, I try to output the image but it just doesn't appear to work. What I want to do is cache the images onto my filesystem, send them to S3 and I want to use the location of the image from my S3 bucket rather than my filesystem. My code looks like below:
In my rails console, I do this just to check the image url:
1.9.3p125 :002 > a.image
=> http:://s3-eu-west-1.amazonaws.com/ramen-hut/pictures/1.jpg?1343645629
1.9.3p125 :003 >
I use Paperclip in my app, is it supposed to add the url as "http:://"? Seems rather weird. The code in my index.html.erb looks like this:
<li>
<%= movie.title %>
<%= image_tag movie.image.url %>
</li>
But this results in the following html:
<li>
Cowboy Bebop
<img alt="1" src="/assets/http:://s3-eu-west-1.amazonaws.com/ramen-hut/pictures/1.jpg?1343645629">
</li>
Why does it include the '/assets'/ before my URL?
I configured Paperclip to set up the image url for my European S3 Bucket following a tutorial. So in my environment.rb, I've got this:
#Signature correction for Paperclip and AWS
AWS::S3::DEFAULT_HOST = "s3-eu-west-1.amazonaws.com"
And I've got an aws-signature.rb file in my initialisers directory with this code:
#Makes Paperclip use the correct URL for images
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
}
There's a problem with the URL : http::// instead of http:// so image_tag doesn't know it's an absolute URL.
How do you generate these URLs? Gem or your own code?
In my mailer views, I include images as follows:
<%= image_tag "header.png" , :alt => "" %>
Which results in the following HTML in the generated email
<img alt="" src="http://example.com/assets/header-247cf573710c22ec2c14eafefeb4c7c1.png">
However, in the case of images used in emails, I would prefer NOT to include the fingerprinting. If I change the header image slightly, I would prefer that when a user drags up an old email, they see the new image, rather then getting an error because the old, fingerprinted URL is no longer valid.
In Rails 3.1.1 both versions of assets are available, and you can use the :digest => false option to make Rails give you the plain path to the asset
<image alt="" src="<%= asset_path 'header.png', :digest => false %>" />
You can set this digest for the entire project in your development or production environment config file by adding the below:
# Generate digests for assets URLs
config.assets.digest = false