Skip to content

Instantly share code, notes, and snippets.

@andrekibbe
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save andrekibbe/d7572e975da96c6c2df6 to your computer and use it in GitHub Desktop.

Select an option

Save andrekibbe/d7572e975da96c6c2df6 to your computer and use it in GitHub Desktop.
Working code to host images separately in Development and Production
# For Alex Yang's Udemy course: The Startup's Guide to Ruby on Rails
# https://www.udemy.com/the-startups-guide-to-web-development-with-ruby-on-rails
class Listing < ActiveRecord::Base
if Rails.env.production?
has_attached_file :image,
:styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
belongs_to :user
else
has_attached_file :image,
:styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
# Previous code from earlier lecture (25 or 26). Lines 13 & 19-24 added for lecture 27.
validates :name, :description, :price, presence: true
validates :price, numericality: { greater_than: 0 }
validates_attachment_presence :image
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
belongs_to :user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment