Skip to content

Instantly share code, notes, and snippets.

@kieetnvt
Created November 30, 2017 14:47
Show Gist options
  • Save kieetnvt/5258c9c5417a15e7f1fcd22d898161dc to your computer and use it in GitHub Desktop.
Save kieetnvt/5258c9c5417a15e7f1fcd22d898161dc to your computer and use it in GitHub Desktop.
Set image paperclip with rails console
class ProductPhoto < ActiveRecord::Base
  belongs_to :product
  has_attached_file :photo, styles: {large: '1024x1024', medium: '300x300', small: '150x150#', item: '150x'}
  validates_attachment_content_type :photo, content_type: /\Aimage/
  validates :photo, presence: true
end
# in rails console
ProductPhoto.all.each do |pp|
  pp.photo = File.open("#{Rails.root}/app/assets/images/example-image.png", "rb")
  pp.save
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment