【问题标题】:[RAILS]: cloudinary display photo1[RAILS]:云显示照片1
【发布时间】:2018-12-18 05:47:53
【问题描述】:

您好,我是 Ror 的新手, 在我的新应用上,我使用 cloudinary 和 attachinary gem 在我的产品页面上显示我的照片。 我没有成功在我的展示页面上只显示与我的产品相对应的第一张照片,而不是我的所有产品照片。 有没有什么云里雾里的帮手说我想在这个地方展示product.picture 1 或product.picture 2? 感谢您的帮助,

这是我的代码: 课程.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 %>

【问题讨论】:

  • 你用什么上传照片?回形针还是载波?
  • 我用的是carrierwave
  • 你试过了吗:&lt;%= image_tag photo_url, width: 400, height: 200, crop: :fill %&gt;,因为这是使用carrierwave时显示图像的方式
  • 这也不好用 :-(

标签: ruby-on-rails image helper cloudinary


【解决方案1】:

所以,如果您只想显示 @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.

【讨论】:

    【解决方案2】:

    请尝试使用 url 而不是路径

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

    如果它不起作用,请告诉我

    【讨论】:

      猜你喜欢
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2019-11-06
      • 2021-10-17
      • 1970-01-01
      • 2012-08-09
      • 2013-11-09
      相关资源
      最近更新 更多