Created
July 10, 2013 14:56
-
-
Save Heavyblade/5967016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # == 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