Skip to content

Instantly share code, notes, and snippets.

@Heavyblade
Created July 10, 2013 14:56
Show Gist options
  • Select an option

  • Save Heavyblade/5967016 to your computer and use it in GitHub Desktop.

Select an option

Save Heavyblade/5967016 to your computer and use it in GitHub Desktop.
# == Schema Information
#
# Table name: libraries
#
# id :integer not null, primary key
# image :string(255)
# file_size :integer
# user_id :integer
# content_type :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class Library < ActiveRecord::Base
attr_accessible :image, :file_size
mount_uploader :image, LibraryUploader
include Rails.application.routes.url_helpers
belongs_to :user
before_save :update_asset_attributes
paginates_per 20
private
def update_asset_attributes
if image.present? && image_changed?
self.content_type = image.file.content_type
self.file_size = image.file.size
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment