Refactor budget's phase max description lenght from Budget to Phase model
This commit is contained in:
@@ -41,10 +41,6 @@ class Budget < ActiveRecord::Base
|
|||||||
send("description_#{phase}").try(:html_safe)
|
send("description_#{phase}").try(:html_safe)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.description_max_length
|
|
||||||
2000
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.title_max_length
|
def self.title_max_length
|
||||||
80
|
80
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Budget
|
class Budget
|
||||||
class Phase < ActiveRecord::Base
|
class Phase < ActiveRecord::Base
|
||||||
|
DESCRIPTION_MAX_LENGTH = 2000
|
||||||
|
|
||||||
belongs_to :budget
|
belongs_to :budget
|
||||||
belongs_to :next_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id
|
belongs_to :next_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id
|
||||||
@@ -7,7 +8,7 @@ class Budget
|
|||||||
|
|
||||||
validates :budget, presence: true
|
validates :budget, presence: true
|
||||||
validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: Budget::PHASES }
|
validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: Budget::PHASES }
|
||||||
validates :description, length: { maximum: Budget.description_max_length }
|
validates :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
|
||||||
validate :dates_range_valid?
|
validate :dates_range_valid?
|
||||||
|
|
||||||
scope :enabled, -> { where(enabled: true) }
|
scope :enabled, -> { where(enabled: true) }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<% Budget::PHASES.each do |phase| %>
|
<% Budget::PHASES.each do |phase| %>
|
||||||
<div class="margin-top">
|
<div class="margin-top">
|
||||||
<%= f.cktext_area "description_#{phase}", maxlength: Budget.description_max_length, ckeditor: { language: I18n.locale } %>
|
<%= f.cktext_area "description_#{phase}", maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, ckeditor: { language: I18n.locale } %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user