2

I'm trying to get an image to show up, but it's just not working. Mind you, this is my very first Ruby app (self-programmed product) and I cloned the Repo, so my apologies in advance if I'm not providing all the required information from the get-go or missing a rather simple oversight.

Here is my screenshot of my image not displaying:

enter image description here

I created the graphic in Illustrator and exported it was a png. I then added it to the right project folder. The image is called AIQtshirt.png and here's the code snippet:

 {
  'count' => 15,
  'html' => 'AutonomIQ<br>T-shirt',
  'class' => 'three',
  'image' => ActionController::Base.helpers.asset_path(
    'refer/AIQtshirt.png') 
  }

In fact, when I use the image that was there there before (from the Repo I cloned), it works. This image is called truman.png and it's in the same folder that I put the AIQtshirt.png file:

enter image description here

Here's the code snippet from using the initial placeholder that was in the repo when I cloned it:

{
  'count' => 15,
  'html' => 'AutonomIQ<br>T-shirt',
  'class' => 'three',
  'image' => ActionController::Base.helpers.asset_path(
    'refer/truman.png')
}

If it's easier to look at the repo it can be referenced here. https://github.com/harrystech/prelaunchr

I can imagine there's something I'm forgetting to do in another folder of the repo.

Here's the string I got when I edited the repo with the code provided in the comments:

enter image description here

image of source code of broken image

Image of the source code of the image originally in the repo

Thanks in advance for your help!

Update: Here is the code:

<% stops.each do |stop| %>
    <li class="product brandon <% if stop["selected"] %>selected<% end %> <% if stop["class"] == 'five' %>last<% end %>">
      <div class="circle"><%= stop["count"] %></div>
      <div class="sep"></div>
      <p><%= stop["html"].html_safe %></p>

      <div class="tooltip">
         <img src="<%= stop["image"] %>" height="254">
      </div>
sjmario38
  • 33
  • 5
  • 1
    Hi sjmario38, is it possible to share the path to the image just to be sure that it is in the right place? – Abhinay Apr 03 '20 at 06:08
  • HI @Abhinay my apologies in advance for my naivety. By path, do you mean the folder where my image is located in the GitHub repo? If so it's: /Documents/GitHub/prelaunchr/app/assets/images/refer/ I hope this helps. – sjmario38 Apr 03 '20 at 14:09

1 Answers1

1

How to debug

A way to debug this would be to edit your app/views/users/refer.html.erb to show the image url visibly on your page. You should find this piece (assuming it relates to image you are not able to see):

<div class="tooltip">
  <img src="<%= stop["image"] %>" height="254">
</div>

and replace it with something like this:

<div class="tooltip">
  My img url as seen by rails is: <%= stop["image"] %> 
  <br/> Hm, is this where my image is? Have I made a typo? :)
  <img src="<%= stop["image"] %>" height="254">
</div>

What worked

Since I didn't want to let this hanging unanswered I went and cloned pre-launcher app myself and was able to make the image display. So, I'll assume you're running your dev server using foreman start -f Procfile.dev and that everything from README file of the pre-launcher repository went well for you (e.g. rake db:create, rake db:migrate)

So, here is what I did. I took some random shaver photo from the internet and named it fancy-shaver.png and saved it in: app/assets/images/refer folder.

Then I edited app/models/user.rb (just the first referal step) and put this:

 REFERRAL_STEPS = [
    {
      'count' => 5,
      'html' => 'Fancy shaver',
      'class' => 'two',
      'image' =>  ActionController::Base.helpers.asset_path(
        'refer/fancy-shaver.png') # <- this is what I changed
    },
    {
      'count' => 10,
      'html' => 'Truman Handle<br>w/ Blade',
      'class' => 'three',
      'image' => ActionController::Base.helpers.asset_path(
        'refer/truman@2x.png')
    },
    # ... the rest I didn't touch

Then I opened, http://localhost:5000/refer-a-friend and same as you I experienced the image was missing. Then I just did: CTRL+C where my server was running and started it again. The image was visible after that. And below is what I got:

enter image description here

If it doesn't work still

Advice: when things go south, especially when learning something new, sometimes the best thing to do is to restart everything (clone app in a new folder) and do exactly the steps that worked (e.g. you can try what I did above after following the app readme).

draganstankovic
  • 5,382
  • 1
  • 27
  • 33
  • Wow, I think it's working. I was able to add that little snippet to test/debug and that string showed up in the app viewer... Where do you suggest I go from here? All of images have this snippet. – sjmario38 Apr 03 '20 at 20:59
  • can you share the string you got by editing the question? – draganstankovic Apr 03 '20 at 22:20
  • for sure - I attached the image to the question of how the app reacted. The sentence you suggested to type showed up in the picture. – sjmario38 Apr 03 '20 at 22:52
  • can you check page source in browser and add the part around that image instead of the screenshot... – draganstankovic Apr 03 '20 at 23:56
  • Hi @draganstankovic - I've inspected the image (the one that was there before and in the repo) in the browser and it shows us as:
    " My img url as seen by rails is? Have I made a typo :) " == $0
    The image that I tried to put in it's place still shows up as a broken image and the source shows up as:
    " My img url as seen by rails is? Have I made a typo :) " == $0
    – sjmario38 Apr 04 '20 at 02:58
  • I added the edit section in my answer, would be nice if you could share (as edit of your question what are the modifications you have made). Specifically, this `... == $0` this part that you shared in comment seems weird. – draganstankovic Apr 04 '20 at 05:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/210916/discussion-between-sjmario38-and-draganstankovic). – sjmario38 Apr 04 '20 at 06:20