Trouble creating a symlink in Rails public folder
Asked Answered
A

1

7

In my Rails app I want to create a symlink in public/ that links to another folder. I can create the symlink and navigate through it but I can't seem to get Rails to serve images out of it. Is there a trick? Is it even possible?

I have a folder with thousands of PNGs that I don't want to just plop into the asset pipeline. They will rarely, if ever, change so pipeline largely unnecessary. Thoughts?

lrwxr-xr-x  1 meltemi  staff   pages -> /Volumes/BigDisk/pages_root

but when I try to hit localhost:3000/pages/F-C2E-439_00002_1.png I get:

Routing Error

No route matches [GET] "/pages/F-C2E-439_00002_1.png"
Alyse answered 20/9, 2012 at 21:33 Comment(0)
G
0

You can use send_file to avoid that route error, you wont be able to visit the image directly but you can load it into a view using a helper method to do something like this:

send_file "#{Rails.root}path/to/your/image", type: 'image/jpeg', disposition: 'inline'

Only issue (for me) is that if I have to send more than 3 large images, like the ones people upload directly from their phones, the first image will break on iOS safari and only half load.

Gannie answered 1/12, 2020 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.