[RAILS]: 云显示 photo1

[RAILS]: cloudinary display photo1

大家好,我是 Ror 的新手, 在我的新应用程序中,我使用 cloudinary 和 attachinary gem 在我的产品页面上显示我的照片。 我没有成功在我的展示页面上只显示与我的产品对应的第一张照片而不是我所有的产品照片。 是否有任何 cloudinary helper 说我希望 product.picture 1 或 product.picture 2 显示在这个地方? 感谢您的帮助,

这是我的代码: lesson.html.erb

   <% @lesson.photos.each do |photo| %>
   <%= cl_image_tag photo.path, width: 400, height: 200, crop: :fill %>
   <% end %>

_form.html.erb:

<%= simple_form_for(@lesson) do |f| %>
   <%= f.input :name %>
   Photo 1  <%= f.input :photo %>
   <%= f.input :photo_cache, as: :hidden %><br>
   Photo 2  <%= f.input :photo %>
   <%= f.input :photo_cache, as: :hidden %><br>
   <%= f.button :submit %>
 <% end %>

请尝试 url 而不是路径

   <%= cl_image_tag photo.url, width: 400, height: 200, crop: :fill %>

如果它不起作用请告诉我

因此,如果您只想显示来自@lessons.photos 数组的特定照片

 <% image_tag @lesson.photos.first.photo_url %>

或者第二个你做

 <% image_tag @lesson.photos.second.photo_url %>

等等!!这是你问的吗?

或者如果您的代码适合您,那么:

 <%= cl_image_tag @lesson.photos.first.path, width: 400, height: 200, crop: :fill %>

或者你也可以

@lesson.photos[0] for first and @lesson.photos[1] for second photo & so on.