I am using Rails 5 and Wicked PDF to render a PDF. On my localhost everything works fine but on my Heroku production server the image is not being rendered. First guess of course is that the image is only available on localhost but that's not the case.
If I render the same view as HTML the image is available but as PDF the image does not show.
<%= wicked_pdf_image_tag 'logo-invoice.jpg', class: 'logo' %>
It shows only a small grey square. The Rails log does not show any errors. I event tried the full URL without using Rails tags:
<img src="https://example.com/assets/logo-invoice-759b0991be66c5119a10b30680ad8902eaceacc33cfcc04afbc839d3ec404870.jpg">
Still no success. Problem is I don't know where to start debugging this?
Any ideas?
Wicked PDF can have issues rendering images from the asset pipeline. Try using the wicked_pdf_asset_base64 helper method i.e.
<%= image_tag wicked_pdf_asset_base64('logo-invoice.jpg'), class: 'logo' %>
Related
I have a rails 4 application and I'm using image_tags throughout the application,
I'm trying to show images on twitter. If I view the source the img src tag seems fine and I can view the image using the url that's in the img src tag.
Images in my assets folder display fine.
Any ideas what's causing this?
Thanks
It's simple, Use
<%= image_tag "https://pbs.twimg.com/media/DYKjGQLW4AAh9fI.jpg" %>
Is this something you were asking?
I have problem with my app in rails . i am creating a simple blog in rails. but images not loaded on browser . i have put images on app/assets/images.
If you put file on assets folder, you should using pipeline, like:
<%= image_tag 'profile.png' %>
Or if all you want is the path to image without tag:
<%= asset_path 'profile.png' %>
Moreover, for using path without pipeline like host/img/profile.png, you should put images on:
/public/img/profile.png
I've done the assets pipeline for my rails project and everything is working fine, except on the dynamic posts page, like http://localhost:3000/posts/2, where images doesn't load. Everywhere else it works fine.
In console I get this error:
ActionController::RoutingError (No route matches [GET]
"/posts/assets/logo.png")
But I used src="assets/m1.jpg in image tag but in the console error the link is different!
What am I missing?
If the image tag has the following exact image path specified:
<img src="assets/m1.jpg" etc="etc">
...then the browser will treat that as a relative URL and try to look it up relative to the URL of the current page, which is http://localhost:3000/posts/2.
As a result, the browser will look for an image with this URL: http://localhost:3000/posts/assets/m1.jpg, which is exactly what's happening in your case.
Try using the image_tag helper instead:
<%= image_tag "m1.jpg" %>
Links that don't start with a / look within the same "folder" you're currently in. Thus when you're on localhost:3000/posts/2 you're in the posts 'folder' and so it looks for localhost:3000/posts/assets/m1.jpg.
If your start a link with a / it'll look from the top of the current site localhost:3000, thus /assets/m1.jpg will look for localhost:3000/assets/m1.jpg which is where you want it to be looking.
In your code you, can use the image_tag helper instead of manually writing out your image tags:
image_tag('m1.jpg') # <img alt="M1" src="/assets/m1.jpg" />
You should use the helper <%= image_tag('m1.jpg') %> and put your image in the assets/images/ directory.
The helper will generate the correct path to the image
Hi I'm very new to rails and came up with this issue. I need your help. Please.
Activeadmin parses the code as raw text so i used<%= raw(#classroom.body) %> in my show.erb to unescape the html tags. but i figured this is the reason why it escapes the ruby video_tag.
I checked out the activeadmin arbre but didn't understand it. i also tried using html video tags but for some reason it shows the video template but doesn't connect to the video file in app/assets/videos.
But when I parse the HTML code directly in the show.erb, the video works perfectly.
The video file can be found in app/assets/videos/Heather.mp4
<%= video_tag "Heather.mp4", :controls => true %>
The first picture is how it looks like in the web browser
The second is the html code in active admin
The third is my show.erb file
The raw method produces raw HTML, not raw ERB. You won't be able to parse your <%= %> tags from there.
Reference the Rails Docs for raw
Using Rails, I am creating my first web-site. And I have a problem like this: I can't insert an image in my page (index.html.erb).
I put an image named "main.png" in directory "app/assets/images", and wrote that:
<img src="main.png">
But my image isn't displayed correctly. What I'm doing not right?
You should use the provided helpers by Rails to "automagically" detect paths, fingerprints, ...:
<%= image_tag "main.png" %>
Anyway, I recommend you to read the asset pipeline guides to understand how the assets works in Rails: http://guides.rubyonrails.org/asset_pipeline.html
You should use Rails helpers as markets pointed out.
By the way, the name of the image file should be the same you use as the parameter of image_tag method. You are referencing your image as main.png when the image file is main.jpg
<%= image_tag "main.jpg" %>