app/models/binda/field_group.rb in binda-0.0.6 vs app/models/binda/field_group.rb in binda-0.0.7
- old
+ new
@@ -17,23 +17,29 @@
extend FriendlyId
friendly_id :default_slug, use: [:slugged, :finders]
after_create :update_position
- # CUSTOM METHODS
- # --------------
- # https://github.com/norman/friendly_id/issues/436
- def should_generate_new_friendly_id?
- slug.blank?
- end
+ # Friendly id preference on slug generation
+ #
+ # Method inherited from friendly id
+ # @see https://github.com/norman/friendly_id/issues/436
+ def should_generate_new_friendly_id?
+ slug.blank? || name_changed?
+ end
+ # Set slug name
+ #
+ # It generates 4 possible slugs before falling back to FriendlyId default behaviour
def default_slug
[ "#{ self.structure.name }-#{ self.name }",
"#{ self.structure.name }-#{ self.name }-1",
"#{ self.structure.name }-#{ self.name }-2",
"#{ self.structure.name }-#{ self.name }-3" ]
end
+ #
+ # Sets the validation rules to accept and save an attribute
def is_rejected( attributes )
attributes['name'].blank? && attributes['field_type'].blank?
end
private