0
votes

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

1 Answers

1
votes

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.