I upload files (PDF's only) using paperclip and now want to display these as a PDF in a view.
This gives me an empty frame <iframe src="<% #document.file %>"></iframe>
This results in an image <%= image_tag #document.file(:large) %>
the files are stored in postgress.
You have an syntax "issue":
<iframe src="<% #document.file %>"></iframe>
Should be
<iframe src="<%= #document.file %>"></iframe>
<!-- notice the equals symbol (=) -->
<!-- which prints something into erb file. -->
Also, I believe you need to use it's url, so I'd be something like this:
<iframe src="<%= #document.file.url(:large) %>"></iframe>
More info - What is the difference between <%, <%=, <%# and -%> in ERB in Rails?
<iframe src= <%= #document.url.html_safe %> width="595" height="485" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC; border-width:1px; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe>
https://scalified.com/2018/01/16/injecting-pdf-html-page/
Related
Using Rails 6 / Ruby 6:
I'm trying to insert an image path into an SVG image tag but somehow the path slashes are getting stripped out.
<% imgpath = asset_path(challenge.imgname) %>
<%= logger.debug "Asset: " + imgpath %>
Outputs the expected:
Asset: /assets/shower.jpg
But inside my SVG image tag:
<image "<%= asset_path challenge.imgname %>" height="100%" width="100%" preserveAspectRatio="xMidYMid slice" />
(and upon "Inspecting" in Chrome)
It shows up as:
<image " assets shower.jpg " height="100%" width="100%"
preserveAspectRatio="xMidYMid slice"></image>
Using raw does not seem to change this behaviour.
Mysteriously "view source" in Chrome does actually show the path:
<image "/assets/greencommute.jpg" height="100%" width="100%" preserveAspectRatio="xMidYMid slice" />
But regardless the image does not render.
Any clues about what's going on?
Thanks in advance.
image tag requires href attribute:
<image href="<%= asset_path challenge.imgname %>" height="100%" width="100%" preserveAspectRatio="xMidYMid slice" />
in your current code rendered url is parsed by browser as an attribute name (and not only browser - note the code highlight color)
I making a blog part with a buyed template.
I'm looking for add image in div. Something like that.
<div class="card card-raised card-background" style="background-image: url('<%= image_tag blog.couverture.url(:hd) %>')">
<div class="card-body">
...
Unfortunatly it's not working. So I looking for help after one hour of research on internet.
Thank you for you help.
Your image must be in "assets/images" folder on your rails proyect, then try this:
<div>
<img src="<%= asset_path 'image_name.format' %>" alt="">
</div>
I used the following code in my show.html.erb file to load a youtube video. The video loads but any code after this is not executing.
<p>
<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/<%=#video.youtubeid%>"
frameborder="0"/>
</p>
Change it to
<p>
<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/<%=#video.youtubeid%>"
frameborder="0">
</iframe>
</p>
Refer this post
You should be able to use the <%= 'no line break' -%> syntax, as in:
<iframe id="ytplayer" type="text/html" width="640" height="390"
src="http://www.youtube.com/embed/<%= #video.youtubeid -%>"
frameborder="0">
</iframe>
Notice the extra dash at the end -%>
This must be very simple. But I just can't seem to find the proper solution.
I have a model with an embedded video attribute.
I made it happen like this:
On my show page
<iframe width="560" height="315" src="<%= #trip.youtube %>" frameborder="0" allowfullscreen></iframe>
Everything works fine, but the thing is that i don't want to show this part if the youtube url is blank. Otherwise I am left with a huge white space, which I don't need.
I've tried to play around with unless or if conditions
<% if #trip.youtube.blank? %>
<iframe width="0" height="0" src="<%= #trip.youtube %>" frameborder="0" class="hidden" allowfullscreen></iframe>
<% else %>
<iframe width="560" height="315" src="<%= #trip.youtube %>" frameborder="0" allowfullscreen></iframe>
<% end %>
But I'm doing something wrong.
Any suggestions for a better way ?
Thanks.
Why not just use:
<% if #trip.youtube.present? %>
<iframe width="560" height="315" src="<%= #trip.youtube %>" frameborder="0" allowfullscreen></iframe>
<% end %>
And leave it at that?
aaa... such a dumb mistake.
In my _form I had:
<div class="field">
<%= f.label :youtube %><br />
<%= f.text_field :youtube,:value => 'http://' %><br />
</div>
Since the field had already - http://, either way, with or without youtube url, rails didn't identify it as blank :))
needs to be simply:
<div class="field">
<%= f.label :youtube %><br />
<%= f.text_field :youtube %><br/>
</div>
and
<% if #trip.youtube.present? %>
<iframe width="560" height="315" src="<%= #trip.youtube %>" frameborder="0" allowfullscreen></iframe>
<% end %>
Works like a charm. Thanks :)
When I put
<iframe width="560" height="349" src="<%= #video.link %>"></iframe>
Everything shows up fine. But the actual video won't play.. what am I doing wrong?
<iframe width="560" height="349" src="http://youtu.be/PF9-lstnLvo">
<html lang="en" dir="ltr">
</iframe>
HELP!!
Wrong src at iframe, it need to be like:
http://www.youtube.com/embed/PF9-lstnLvo
You need to add code:string to you Video model.
Or method code, which return you this code from #video.link like this:
def code
self.link.split('/').last if self.link
end
And replace erb:
<iframe width="560" height="349" src="<%= "http://www.youtube.com/embed/"+#video.code %>"></iframe>