Sha256: d070395d40a7f35ac57036141d4d4c2069914acd532758fe056da596fc4b8184
Contents?: true
Size: 510 Bytes
Versions: 1
Compression:
Stored size: 510 Bytes
Contents
ActiveSupport.on_load(:active_record) do def self.acts_as_permalinkable source_column = :name, target_column = :permalink validates target_column, presence: true, uniqueness: true before_validation :set_permalink, if: Proc.new{ |record| record.send(target_column).blank? } define_method(:to_param){ send(target_column) } protected define_method(:set_permalink){ src = send(source_column) send("#{target_column}=", src.parameterize.presence || SecureRandom.hex(3) ) } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_permalinkable-0.0.1 | lib/acts_as_permalinkable.rb |