From ffb4c0f7caf785c531baa2ce33dd794455cac22f Mon Sep 17 00:00:00 2001 From: Jaques Dias Date: Sat, 7 Oct 2017 13:37:01 -0300 Subject: [PATCH] Update slug before save a document --- app/models/document.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/document.rb b/app/models/document.rb index a037179..10c8683 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # - + class Document < ActiveRecord::Base belongs_to :category + before_save :update_slug extend FriendlyId friendly_id :name, use: :slugged @@ -23,4 +24,10 @@ class Document < ActiveRecord::Base validates :name, :length => { :minimum => 2 } validates :name, :uniqueness => true validates :link, :url => true + + private + + def update_slug + self.slug = name.parameterize + end end