Sutto / slugged

Super simple slugs for ActiveRecord 3+, with slug history. Formerly known as Pseudocephalopod.
MIT License
86 stars 16 forks source link

Concatenate two or more fields before doing the magic? #8

Closed eemi closed 13 years ago

eemi commented 13 years ago

I'm working on a project where I need to concatenate two fields and then get a slugg from them.

I can achieve this by creating an extra field, but this means having that extra field just for this. I was wondering if this could be done with slugged directly.

Thanks in advance, Emiliano

Sutto commented 13 years ago

Hi Emiliano,

The easiest way is to define two methods: one for your slug source e.g;

def full_name
  "#{first_name} #{last_name}"
end

And then a second one, full_name_changed? - essentially,

def full_name_changed?; first_name_changed? || last_name_changed?; end

With that done, you should be able to do is_sluggable :full_name and it'll do it's magic - If not, let me know and I'll fix it to make it work since that's a bug.

eemi commented 13 years ago

Thank you very much. I will try this!