1

I want to allow users to renew the slug of an entry by clicking a checkbox.

I know the function should_generate_new_friendly_id? , but not how to use it in this case since it is defined in the model and cannot read params attributes.

Thanks for any ideas!

Railsana
  • 1,813
  • 2
  • 21
  • 30

1 Answers1

2

On the model, you can add an attr_accessor to test for this case

attr_accessor :should_generate_new_friendly_id

before_save :generate_new_friendly_id, :if => :should_generate_new_friendly_id

def generate_new_friendly_id
  self.friendly_id = ...
end

Then, in the form, you can provide a checkbox with the name 'should_generate_new_friendly_id'. It should all work as you expect...

Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70