nzoLogic
nzoLogic

Reputation: 443

heroku postgress images not displaying ruby on rails

The Problem

Having trouble with displaying users uploaded photo from heroku postgress in a materialize slider. It only displays once a user uploads a new picture. Anything previously uploaded (while deployed on heroku) doesn't display. I also get a Failed to load resource 404 in the browser console on the page that is supposed to display the image slider.

Attempted solutions

I've tried running the terminal command 'heroku run rails assets:precompile' which still does not work. My local version works fine with no problems. I'm not sure if this is a Materialize looking in the

Here's the view

enter image description here

Here's the erd

enter image description here

Upvotes: 0

Views: 249

Answers (2)

puneet18
puneet18

Reputation: 4427

Heroku is read-only system so you can't upload images to heroku.

You have to upload images to Amazone S3 or cloudinary servers using carrierwave gem.

Upvotes: 1

Michał Młoźniak
Michał Młoźniak

Reputation: 5556

Running heroku run rails assets:precompile will have no effect. Whenever you invoke heroku run command, a new one-off dyno is created, the command is executed and then dyno is killed. Those changes will not be reflected on your actual web server. And btw it should be rake assets:precompile.

Second thing, assets:precompile works for application static assets like javascripts, stylesheets and images that are part of your web design. You don't use it for user-uploaded images.

I think your problem is that you just upload user photo somewhere inside your app directory. Maybe in public or so like it was mentioned in the comment. This won't work on Heroku, because you don't have persistent storage. Any changes on disk will be gone after next deploy or restart. What you need to do is to store uploaded files somewhere else, ie. Amazon S3. If you are using some gem for uploading (carrierwave or paperclip), it should pretty easy to setup.

Upvotes: 0

Related Questions