Only update slug if empty or model condition is met
This commit is contained in:
@@ -180,6 +180,10 @@ class Budget < ActiveRecord::Base
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_slug?
|
||||||
|
slug.nil? || drafting?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,11 @@ class Budget
|
|||||||
def single_heading_group?
|
def single_heading_group?
|
||||||
headings.count == 1
|
headings.count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def generate_slug?
|
||||||
|
slug.nil? || budget.drafting?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,5 +28,11 @@ class Budget
|
|||||||
investments.empty?
|
investments.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def generate_slug?
|
||||||
|
slug.nil? || budget.drafting?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module Sluggable
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_validation :generate_slug
|
before_validation :generate_slug, if: :generate_slug?
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_slug
|
def generate_slug
|
||||||
|
|||||||
Reference in New Issue
Block a user