Skip to content

Instantly share code, notes, and snippets.

@RobinDaugherty
Last active December 19, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinDaugherty/5919492 to your computer and use it in GitHub Desktop.
Save RobinDaugherty/5919492 to your computer and use it in GitHub Desktop.
class Picture < ActiveRecord::Base
attr_accessible :picture, :picture_105px_width, :picture_120px_width
has_many :pin
end
class Pin < ActiveRecord::Base
belongs_to :picture_record, class_name: Picture
def picture
picture_record || read_attribute('picture')
end
end
<% if @pin.picture.respond_to?(:picture_105px_wide) && @pin.picture.picture_105px_wide.present? %>
<%= image_tag @pin.picture.picture_105px_wide %>
<% else %>
<%= image_tag @pin.picture %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment