Show image from another model using id upload by paperclip Rails 3

morfious902002

How do I access Image.photo using its id from Pin models view?

Currently I am doing this and it gives me random number if I remove the image_tag or bank image space.

<td><%= image_tag Image.find_by_id(pin.pic) %></td>

This one gives me undefined method `photo' for nil:NilClass

<td><%= image_tag Image.find_by_id(pin.pic).photo.url(:small) %></td>


class Pin < ActiveRecord::Base
  attr_accessible :board, :pic, :pin_time, :user, :apic, :photo
  belongs_to :auser, :class_name => 'User', :foreign_key => 'user' 
  belongs_to :apic,   :class_name => 'Image',:foreign_key => 'pic'
end


class Image < ActiveRecord::Base
  attr_accessible :description, :uid, :web_url, :photo, :photo_file_name,:photo_content_type, :photo_file_size, :photo_updated_at, :id
  has_attached_file :photo, :styles => { :small => "150x150>", :medium => "300x300", :large => "600x600"}

  belongs_to :user

  validates_attachment_presence :photo
  validates_attachment_size :photo, :less_than => 5.megabytes
  validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
end
DeeY

Why not simply

pin.apic.photo.url(:small)

Or are you looking for something else completely?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Rails 4: Multiple image upload using paperclip

Paperclip image upload in rails

How can i image upload on another Ruby on Rails application using paperclip?

How to Upload Multiple Image in Rails 4 Using Paperclip

Rails 4 - Paperclip - Upload an image using DATA URI

Ruby on Rails: Help in multiple image upload using paperclip with different process

Rails direct upload to Amazon S3 using Activeadmin + Paperclip

Upload Image From seed file using paperclip gem

Rails Multiple image upload (paperclip, carrerwave)

Seeding a model with a paperclip image in ruby on rails

Using Paperclip with Celluloid in Rails 3?

Rails upload a picture using paperclip and devise

How to upload image into Gmaps4rails's marker using Paperclip?

Image in heroku uploaded using paperclip does not show

get only first image using paperclip rails

Rails 4 and paperclip - Stop the :original style file upload to copy it from an S3 remote directory

Active admin multiple image upload with paperclip Rails 5

Using attributes from one model in another Rails

Can't upload zip files using ruby on rails and paperclip gem

Upload image to S3 through Heroku by paperclip

RoR, Paperclip and S3 upload image error

Paperclip image resizing in rails

Rails Paperclip upload button not working

Rails file upload (paperclip) on edit

Rails4 + Paperclip (unable to clone from model)

S3 Paperclip rails Can not display image

Show Upload Progress for Image Upload to Amazon S3 using Swift 3 and Amazon SDK

Access image from different view in a view with paperclip gem ruby on rails

Paperclip upload file from mobile