0

I have friendly_id applied and working but now I dont want it to add a slug if the key_type is 4

currently I have

 extend FriendlyId
 friendly_id :value, :use => :scoped, :scope => [:category_item_key, :category_item]

and tired applying an if statement in the model like below

  if :key_type == 4
  else
   extend FriendlyId
   friendly_id :value, :use => :scoped, :scope => [:category_item_key, :category_item]
  end

But the if statement doesn't seem to do anything. I figured there might be a built in way in friendly_id for this to be done (couldn't see anything in the docs). Or maybe thee is some other way of getting this done so it wont add a slug if the key_type is equal to 4?

Rob
  • 1,835
  • 2
  • 25
  • 53

1 Answers1

0

How about something like:

before_create :add_slug_if_needed

def add_slug_if_needed
  self.slug = 'hey_look_a_slug' unless key_type == 4
end

I'm suggesting this instead of a FriendlyId approach because conditionally extending modules seems like a can of worms!

jmschles
  • 274
  • 1
  • 6