Chris Bui
Chris Bui

Reputation: 1095

Rails paperclip image data being appended after loop

I'm trying to make a view that shows all of the pictures uploaded by paperclip. I set paperclip up and the images have been uploaded fine so far. But when creating the view, for some reason the picture's object data gets appended after all of the images. My models are setup so that a picture contains an image, which is the uploaded image file itself.

In my controller:

class HomeController < ApplicationController
   def index
      @pictures = Picture.all
   end
end

In my view:

<h2>Pictures</h2>

<%= @pictures.each do |picture| %>
    <div>
        <%= image_tag picture.image.url(:thumb) %>
    </div>
<% end %> 

And this is what I see on the page after all of the pictures.

[#<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: "">]

It's interesting to note that even if I remove all of the code within the loop, the object data still appears, but if I individually load each picture it works fine.

@picture = Picture.find(6)

<%= image_tag @picture.image.url(:thumb) %>

Upvotes: 0

Views: 233

Answers (1)

Cristian Bica
Cristian Bica

Reputation: 4117

replace

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

with

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

the '=' with also return the @pictures array

Upvotes: 1

Related Questions