0

I am following a simple process to call images from database. I will explain my process and problem so that it is easy for you to answer.

  1. In assets/images I will save my images.
  2. In the database I have created t.images:string and will give the image name

How to define the image_tag in the show and index pages.

What I did so far,

  • In show.html.erb <%= image_tag "url#{@post.image}" %>

  • In index.html.erb <%= image_tag post.image.url, :size => "100x100" %>

But I am getting this error

matthey
  • 39
  • 7
  • welcome to SO, for the future question it will be better if you ask question and put the code directly here, this will make other easier to read and answer your question – widjajayd May 11 '20 at 09:11

1 Answers1

0

since post.image is location of your image, you don't need to add .url see line 3 for your correction

<% @posts.each do |post| %>
  <div class="well">
    <%= image_tag post.image, :size => "100x100" %>
    <h3><%= post.title %></h3>
    <p><%= post.body %></p>
    ...
  </div>
<% end %>
widjajayd
  • 6,090
  • 4
  • 30
  • 41