I just went through a similar problem with displaying an image in a PDF 
generated from the gem prawn.

Worked find in development, but not production. prawn knows nothing about 
the asset pipeline or path helpers. I'm sure that the same is true with 
trying to get the path from java/coffee/script.

I even included the path helpers  `  include 
 ActionView::Helpers::AssetTagHelper` but that didn't work with asset_path 
or asset_url. It just didn't didn't work. There must be some hidden magic 
in the asset_path that sets the uuid between the image name and .type.

>From the root url  you can get an image with 
server.com/assets/assets/my-logo-b70c4bbdfd69ea9db2785922c48b8ec1f03c5d8b6bf2be843ee570199cd51743.jpg,
 
but you don't know the precompiled name. Even if you did, it would break in 
development.  Prawn or coffee script does not know about environments.

I finally found a solution, not fond of it,  but it works. Prawn has an 
image method that requires a path and options. I just fell back to the path 
based on rails.root

    image(Rails.root.join('app/assets/images/my_logo.jpg'),width:100 ) 

never tried to serve an image from coffee script and not sure the hack I 
found would work. You are basically ignoring the asset pipeline

Steve






On Wednesday, March 6, 2019 at 6:16:28 AM UTC-6, Colin Law wrote:
>
> I hope someone can help me with an assets problem.  I have had to 
> rebuild a production server and images are no longer getting served. 
> Unfortunately the working system is no more so I can't compare what I 
> have with what used to work in order to help diagnose the problem. 
>
> I am using Rails 4.2 with nginx on an Ubuntu 16.04 server with 
> capistrano to deploy it and I have not changed the application (which 
> is git controlled).  However it is now running on a later version of 
> Ubuntu so the tools there have been updated, including nginx. 
>
> The problem is that image assets are not being served, the javascript 
> and css are working.  I can see (on the server) that the assets have 
> been precompiled and I can see in public/assets image files such as 
> blue_pin-<digest>.png where <digest> is a big long number. 
> However in the browser console I can see it attempt to fetch 
> /assets/blue_pin.png without the digest, and this fails. 
>
> The code in the app that references the image is in coffescript and is a 
> line 
>  @marker_icon_blue = new OpenLayers.Icon('/assets/blue_pin.png', size, 
> offset); 
>
> I used to know how all this is supposed to work, but I have been away 
> from Rails for a while and the brain cells seem to have atrophied 
> rather, and perusing the docs has failed to re-invigorate them 
> sufficiently, so if someone could suggest what might be going on I 
> would be very grateful. 
>
> Colin 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/fe2fde0e-452a-4b53-81d4-a328300c8cac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to