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
|
||||
|
||||
def generate_slug?
|
||||
slug.nil? || drafting?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -13,5 +13,11 @@ class Budget
|
||||
def single_heading_group?
|
||||
headings.count == 1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_slug?
|
||||
slug.nil? || budget.drafting?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,5 +28,11 @@ class Budget
|
||||
investments.empty?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_slug?
|
||||
slug.nil? || budget.drafting?
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@ module Sluggable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_validation :generate_slug
|
||||
before_validation :generate_slug, if: :generate_slug?
|
||||
end
|
||||
|
||||
def generate_slug
|
||||
|
||||
Reference in New Issue
Block a user