Revert changes in Budget::Investment model that added image attachment directly
This commit is contained in:
committed by
Senén Rodero Rodríguez
parent
e38b06a003
commit
886431b43d
@@ -1,7 +1,5 @@
|
|||||||
class Budget
|
class Budget
|
||||||
class Investment < ActiveRecord::Base
|
class Investment < ActiveRecord::Base
|
||||||
MIN_SIZE = 475
|
|
||||||
|
|
||||||
include Measurable
|
include Measurable
|
||||||
include Sanitizable
|
include Sanitizable
|
||||||
include Taggable
|
include Taggable
|
||||||
@@ -19,7 +17,6 @@ class Budget
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
has_attached_file :image, styles: { large: "x#{MIN_SIZE}", medium: "300x300#", thumb: "140x245#" }
|
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :heading
|
belongs_to :heading
|
||||||
@@ -42,10 +39,6 @@ class Budget
|
|||||||
validates :title, length: { in: 4..Budget::Investment.title_max_length }
|
validates :title, length: { in: 4..Budget::Investment.title_max_length }
|
||||||
validates :description, length: { maximum: Budget::Investment.description_max_length }
|
validates :description, length: { maximum: Budget::Investment.description_max_length }
|
||||||
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
|
||||||
validates_attachment :image, content_type: { content_type: ["image/jpeg"] }
|
|
||||||
validates :image_title, presence: true, if: -> { image.present? }
|
|
||||||
validates :image_title, length: { in: 4..Budget::Investment.title_max_length }, if: -> { image.present? }
|
|
||||||
validate :check_image_dimensions
|
|
||||||
|
|
||||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) }
|
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc, id: :desc) }
|
||||||
scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) }
|
scope :sort_by_ballots, -> { reorder(ballot_lines_count: :desc, id: :desc) }
|
||||||
@@ -274,18 +267,5 @@ class Budget
|
|||||||
self.budget_id ||= heading.try(:group).try(:budget_id)
|
self.budget_id ||= heading.try(:group).try(:budget_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_image_dimensions
|
|
||||||
temp_file = image.queued_for_write[:original]
|
|
||||||
unless temp_file.nil?
|
|
||||||
dimensions = Paperclip::Geometry.from_file(temp_file)
|
|
||||||
width = dimensions.width
|
|
||||||
height = dimensions.height
|
|
||||||
|
|
||||||
if width < MIN_SIZE || height < MIN_SIZE
|
|
||||||
errors['image'] << I18n.t("budgets.investments.edit_image.invalid_dimmensions")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user