Sutto / slugged

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

Untitled #4

Closed gzigzigzeo closed 13 years ago

gzigzigzeo commented 13 years ago

I have implemented manual slug edition functionality and wrote tests. See my message in closed issues.

Sutto commented 13 years ago

Hey there Victor, Cheers for the awesome patch. Would it be possible before I pull it in to get should_convert_cached_slug to take into account an option on is_sluggable like :editable so that people can turn this feature on and off?

Cheers

gzigzigzeo commented 13 years ago

Yes, of course. I think it would be useful to disable changing of cached_slug attribute when :editable is set to false, woulnd'nt it?

Let me explain. Let we have a model without my patch.

class Model < ActiveRecord::Base is_sluggable :name end

m = Model.create!(:name => "first") # slug will be "first" m.update_attribute(:name => "second") # slug will be "second" m.update_attribute(:cached_slug => "!!!invalid") # slug will be "!!!invalid", even it is not editable, but I think user should not be able to change this

I conjecture that it can be done by making cached_slug= setter protected when defined, but I am not yet shure. What do you think about it?

Sutto commented 13 years ago

Possibly - I think personally the onus is on the app developer to manage attr_protected / attr_accessible (and mixing them is a bad idea) - Maybe changing the setter method to not work / do nothing would be an alternative solution? In general I like idea, I just dislike the notion of using attr_protected / attr_accessible like that.

gzigzigzeo commented 13 years ago

Okay, let user decide to protect this attr. I'll send a message to you when finish.

gzigzigzeo commented 13 years ago

I have made an :editable option, see tests/editable.rb. See my commit and merge if it is possible or tell me what should I fix.

Sutto commented 13 years ago

Merged in and released as 0.4.0 - cheers for the contribution!

gzigzigzeo commented 13 years ago

Thank you. You have made very useful plugin.