0

I am a beginner at Ruby on Rails and Database stuff and I am having a hard time researching how to display image from PostgreSQL and Sqlite3 database to my website using Ruby on Rails, or in Ruby on Rails.

And my problem is "how to display images from database to my website using Rails", just that.

I started with <%= @real_estate.image %> in my show.html.erb and then what displays to my website is nothing useful like #<ActionDispatch::Http::UploadedFile:0x000000000d4fb548>

2
  • 2
    Does this answer your question? Showing images with Rails from database Commented May 17, 2021 at 15:26
  • I strongly recommend using ActiveStorage to do this, it is really complete and easy to setup, after this, you can implement it in all the models you want without needing additional migrations It comes by default with Rails since version 5.2 Checkout this docs to setup and use. Commented May 17, 2021 at 16:11

1 Answer 1

1

Try something like this:

<%= image_tag @real_estate.image, :alt => 'product_image' %>

My recommendation is to strongly use some cloud storage(like s3 AWS) instead of being inside the database. In the database, save only the url and name of the image.

The fog gem can link your database information with s3 and bring a signed image url.

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

Comments

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.