0

I am new to rails so forgive me if this is a basic question and I'm missing something.

I have a model that stores the location, filename, and extension of an image file. I concat those together and write them into an tag in my model using the image_tag. The tag is being correctly rendered in HTML with the proper path; however the image is showing up blank. I've added the image to app/assets/images so everything should be in its proper place but I can't figure out why the image isn't rendering. Here's what I have:

Model

 class FileInfo < ActiveRecord::Base
    def fullPath
      "#{location}#{fileName}#{extension}"
    end
 end

View

<% @letter.relatedMedia.each do |m| %>
    <%= image_tag(m.file_info.fullPath) %>
<% end %>

when the image tag renders in HTML, I get this as the source:

"/images/letters/some-image-file.jpg"

In my application, the file is stored here:

"app/assets/images/letters/some-image-file.jpg"

Am I storing the file in the wrong place? Is the path not writing out correctly? I'm really not sure where I'm going wrong here.

Any help you can provide would be greatly appreciated!

1 Answer 1

1

Change the path stored in the database to letters/some-image-file.jpg. You don't need the full path because the Rails asset pipeline will find the image for you.

Read about the Rails Asset Pipeline to get a better understanding about how it works.

Sign up to request clarification or add additional context in comments.

4 Comments

Actually, thats what i'm storing. The database has letters/some-image-file.jpg. When it creates the image tag, the source of the img tag (when rendered) is "/images/letters/some-image-file.jpg". It's almost as though its ignoring the asset pipeline (either that or something weird is up with the routes).
If you only store some-image-file.jpg in your db does it render?
No it doesn't. Form all the digging I've done, it appears to be something with my asset pipeline configuration. Writing out "letters/some-image-file.jpg" or just "some-image-file.jpg" causes the image_tag to render the source as "images/letters/" etc etc when it SHOULD be rendering it as "assets/letters/" etc etc. So clearly something is messed up in my asset pipeline config but i haven't the foggiest idea what.
Nevermind. I figured it out. I had the file extension in the database as .jpg but the physical file on the server had an extension of .JPG so the problem was the server wasn't finding the file due to a case sensitivity. Chalk this one up to stupidity on my part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.