app/models/landable/template.rb in landable-1.11.0 vs app/models/landable/template.rb in landable-1.11.1

- old
+ new

@@ -8,11 +8,13 @@ validates_presence_of :name, :slug, :description validates_uniqueness_of :name, case_sensitive: false validates_uniqueness_of :slug, case_sensitive: false + before_save :slug_has_no_spaces + belongs_to :published_revision, class_name: 'Landable::TemplateRevision' has_many :audits, class_name: 'Landable::Audit', as: :auditable has_many :revisions, class_name: 'Landable::TemplateRevision' has_and_belongs_to_many :pages, join_table: Page.templates_join_table_name @@ -59,9 +61,15 @@ self.body = revision.body self.description = revision.description self.slug = revision.slug save! + end + + def slug_has_no_spaces + if self.slug =~ /\s/ # check if whitespace + self.slug = self.slug.underscore.gsub(/[^\w_]/, '_').gsub(/_{2,}/, '_') + end end class << self def create_from_partials! Partial.all.map(&:to_template)