0

rails newbie here I am using friendly_id gem, I have a Page model when I create page a friendly_id slug generate from title given in text field, What i want is to able to edit that slug and do not change on update or when i change the title

here is my Page.rb

     class Page < ActiveRecord::Base

            belongs_to :user
            include Bootsy::Container

            extend FriendlyId

            friendly_id :title, use: :slugged


            validates :title, :presence => true
            validates :user_id, :presence => true

            def should_generate_new_friendly_id?

            end

          end

I know this is a very basic task but I am new in rails. thanks

Majid Mushtaq
  • 319
  • 1
  • 3
  • 14

1 Answers1

1

Done this by adding the following login inside should_generate_new_friendly_id? :

def should_generate_new_friendly_id?
  new_record? || !self.slug.present?
end
Majid Mushtaq
  • 319
  • 1
  • 3
  • 14