I'm having a little trouble trying to display an image that is hosted on another site. Usually I would have the image in my assets pipeline, but on this project I am using an API to grab the image URL that's hosted on another site. I'm trying it this way below, but I feel like it's still pointing to my assets folder. How can I set it to display this image if it meets a conditional? Thanks!
...
<% if article.image_url %>
<%= image_url("<%= article.image_url %>") %><p>
<% end %>
...
Try <%= image_tag(article.image_url) if article.image_url %>
Hope this helps!
I believe you'd need to interpolate article.image_url like so:
<% if article.image_url %>
<%= image_tag article.image_url %><p>
<% end %>
Related
I was using the Bootstrap cards for my index page for my app but wasn't really liking the event details button, I feel it's more modern to just click on the image.
I found SOF articles pointing to how to use clickable images if the image was local and/or hosted somewhere online, but nothing that pointed to using images that are already a part of your database.
The code I had before was:
<% if artist.avatar.attached? %>
<%= image_tag artist.avatar, class: "even-size-artist" %>
<% else %>
<img src=<%= "https://dancewise.s3.amazonaws.com/misc-images/Blank+Avatar.png" %> class="even-size-artist">
<% end %>
The code that I found that will give you the option to have the top image clickable to the appropriate record is as follows:
<% if artist.avatar.attached? %>
<%= link_to image_tag(artist.avatar, class: "card-img-top artist-img").html_safe, artist %>
<% else %>
<img src=<%= "https://dancewise.s3.amazonaws.com/misc-images/Blank+Avatar.png" %> class="card-img-top artist-img">
<% end %>
Hopefully, this helps someone else out there learning RoR!
I am making a very simple rails program and trying to show a picture
Here is my code
<%= link_to course do %>
<%= image_tag "courses/1.png" %>
<% end %>
I put the picture 1.png at the folder courses so it could be show. Very easy to understand. But when I tried to changed to another folder like this
<%= link_to course do %>
<%= image_tag "images/1111.png" %>
<% end %>
I can not show the picture.
Could you please give me some ideas for me with this problem? I know it is easy to understand but I am stucking with this one, please give me some ideas. Thank you very much.
In the index page of my app, i want to display only the first image of a post that has multiple images attached to it.
<% (0...job.images.count).each do |image| %>
<%= image_tag(job.images[image]) %>
<% end %>
I have tried:
<%= image_tag job.images.first.try[image] %>
But get a no method given error
You should be able to treat it as a normal ActiveRecord query
<%= image_tag job.images.first if job.images.attached? %>
Based on the first bit of code you've provided, you should be able to use this:
<%= image_tag job.images.first %>
Assuming that job.images is an array of paths to the images?
I'm having some issues with my project I'm using the image_tag with my DB but every time I want to use it, is not taking the syntaxis this is the message thar I got The asset "ur" is not present in the asset pipeline., this is the code:
<% #articles.each do |article| %>
<%=link_to article_path(article), class:"thumb-link" do %>
<%= image_tag ("#{article.img}") %>
<% end %>
<% end %>
in my DB in the field "img" I got this URL "https://dummyimage.com/700x900/000/C82E0D.jpg"
any idea where do I have my mistake???
I will really appreciate if you can help me with thi issue
I check my code again I found my mistake in the image_tag I need to add the https like this:
<%= image_tag ("https://#{article.img}") %>
and it works
I am using CarrierWave and Amazon S3 to upload images to my application, which is working correctly. But I also want to have the image link to the corresponding Movie. I have tried the following but it doesn't work. I have looked but can't seem to find a solution this simple problem.
<% if #movie.avatar? %>
<%= image_tag(#movie.avatar_url), link_to #movie %>
<% else %>
<img src="http://placehold.it/150x200">
<% end %>
Try this:
<%= link_to image_tag(#movie.avatar_url), #movie %>
Use this
<%= link_to (image_tag(#movie.avatar_url)), #movie %>