PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 10, 2022

[FIXED] How to display image from rails local project folder?

 May 10, 2022     image, ruby-on-rails, twitter-bootstrap     No comments   

Issue

Very basic question, but somehow I can't get it to work. I am trying to have an image located in project's local folder to display on Rails. Additionally, I am using bootstrap; thus I need to declare class: "img-responsive" as well. Here is the original code: <img class="img-responsive" src="assets/img/mockup/img2.jpg" alt="">

I have consulted this post which suggested <%= image_tag("xyz.png", class: "img-responsive img-thumbnail img-circle") %> and rubyonrails guide which suggested image_tag("/icons/icon.gif", class: "menu_icon").

I have tried

<%= image_tag ("assets/img/mockup/img2.jpg", class: "img-responsive")%>

and

<%= image_tag "assets/img/mockup/img2.jpg" %>

But it still does not work. I can confirm that the path is: app/assets/img/mockup/img2.jpg

How can I display the said image on rails app view?


Solution

I was browsing and saw this SO post. I was able to get it work using

<%= image_tag ("/assets/mockup/img2.jpg"), class: "img-responsive"%>

Image path was assets/images/mockup/img2.jpg; omitting images from the image path assets/mockup/img2.jpg solves the issue.



Answered By - Iggy
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing