Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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回形针图像数据在循环后追加_Ruby On Rails_Ruby_Paperclip - Fatal编程技术网

Ruby on rails Rails回形针图像数据在循环后追加

Ruby on rails Rails回形针图像数据在循环后追加,ruby-on-rails,ruby,paperclip,Ruby On Rails,Ruby,Paperclip,我正在尝试制作一个视图,显示所有通过回形针上传的图片。我设置了回形针,到目前为止,图像上传得很好。但在创建视图时,由于某些原因,图片的对象数据会附加在所有图像之后。我的模型被设置为一张图片包含一个图像,这是上传的图像文件本身 在我的控制器中: class HomeController < ApplicationController def index @pictures = Picture.all end end class HomeController

我正在尝试制作一个视图,显示所有通过回形针上传的图片。我设置了回形针,到目前为止,图像上传得很好。但在创建视图时,由于某些原因,图片的对象数据会附加在所有图像之后。我的模型被设置为一张图片包含一个图像,这是上传的图像文件本身

在我的控制器中:

class HomeController < ApplicationController
   def index
      @pictures = Picture.all
   end
end
class HomeController
我认为:

<h2>Pictures</h2>

<%= @pictures.each do |picture| %>
    <div>
        <%= image_tag picture.image.url(:thumb) %>
    </div>
<% end %> 
图片
这就是我在看完所有图片后在页面上看到的

[#<Picture id: 6, created_at: "2012-05-11 18:57:21", updated_at: "2012-05-11 18:57:21", image_file_name: "puppy1.jpg", image_content_type: "image/jpeg", image_file_size: 150222, image_updated_at: "2012-05-11 18:57:21", title: "Doggy", caption: "">, #<Picture id: 7, created_at: "2012-05-11 19:28:56", updated_at: "2012-05-11 19:28:56", image_file_name: "puppy1.jpg", image_content_type: "image/jpeg", image_file_size: 150222, image_updated_at: "2012-05-11 19:28:56", title: "Doggy number 2", caption: "">]
[#,#]
值得注意的是,即使我删除了循环中的所有代码,对象数据仍然会出现,但是如果我单独加载每个图片,效果会很好

@picture = Picture.find(6)

<%= image_tag @picture.image.url(:thumb) %>
@picture=picture.find(6)
更换

<%= @pictures.each do |picture| %>



“=”还返回@pictures数组

每个人都会有这样的感觉,而且还会再次发生:)
<% @pictures.each do |picture| %>