Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 4嵌套表单,如何在编辑表单上显示图像_Ruby On Rails_Paperclip_Nested Forms - Fatal编程技术网

Ruby on rails Rails 4嵌套表单,如何在编辑表单上显示图像

Ruby on rails Rails 4嵌套表单,如何在编辑表单上显示图像,ruby-on-rails,paperclip,nested-forms,Ruby On Rails,Paperclip,Nested Forms,我使用rails 4嵌套表单为我的模型创建表单。模型相册有许多图像。 用于上载图像的部分表单如下所示: <div class="field"> <%= f.fields_for :images do |image_form| %> <div> <%= image_form.file_field(:image_file) %> <%= image_form.link_to_remo

我使用rails 4嵌套表单为我的模型创建表单。模型相册有许多图像。 用于上载图像的部分表单如下所示:

<div class="field">
    <%= f.fields_for :images do |image_form| %>
        <div>
          <%= image_form.file_field(:image_file) %>
          <%= image_form.link_to_remove "Remove this image" %>
        </div>
    <% end %>
</div>

如何为编辑表单上的每个图像显示拇指?当前编辑时仅显示浏览按钮。

您可以使用以下代码显示拇指图像。使用Carrierwave

<div class="field">
  <%= f.fields_for :images do |image_form| %>
    <div>
      <%= image_form.file_field(:image_file) %>
      <%= image_tag image_form.object.image_file_url(:thumb) if image_form.object.image_file?  %>
      <%= image_form.link_to_remove "Remove this image" %>
    </div>
  <% end %>
</div>
如果您使用的是回形针,则必须在以下模型中指定它:

class Album < ActiveRecord::Base
  has_attached_file :image_file, :styles => { :thumb => "50x50>" }
end
&您对回形针的看法将是

<%= image_tag image_form.object.image_file.url(:thumb) if image_form.object.image_file? %>

您可以使用以下代码显示拇指图像

<div class="field">
  <%= f.fields_for :images do |image_form| %>
    <div>
      <%= image_form.file_field(:image_file) %>
      <%= image_tag image_form.object.image_file_url(:thumb) if image_form.object.image_file?  %>
      <%= image_form.link_to_remove "Remove this image" %>
    </div>
  <% end %>
</div>
如果您使用的是回形针,则必须在以下模型中指定它:

class Album < ActiveRecord::Base
  has_attached_file :image_file, :styles => { :thumb => "50x50>" }
end
&您对回形针的看法将是

<%= image_tag image_form.object.image_file.url(:thumb) if image_form.object.image_file? %>