简体   繁体   中英

[RAILS]: cloudinary display photo1

Hi there I m new on Ror, On my new app, I use cloudinary and attachinary gem to display my photos on my product page. I don't succeed to display only the first photo corresponding to my product instead of all my product photos, on my show page. Is there any cloudinary helper to say I want product.picture 1 or product.picture 2 to be displayed at this place? Thks for your help,

Here is my code: 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 %>

please try url instead of path

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

Let me know if its not work

So, if you just want to just display the particular photo from the @lessons.photos array

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

or second you do

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

and so on!! Is this what you are asking?

OR if your code is working for you then:

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

or you can do

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM