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
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.
Comments