Sha256: e58ec2e53acde8bf08d7f9b7a36f7bf5489416227e05710268ddbbe53c0bc220

Contents?: true

Size: 1.56 KB

Versions: 19

Compression:

Stored size: 1.56 KB

Contents

module FriendlyId

=begin

## Reserved Words

The {FriendlyId::Reserved Reserved} module adds the ability to exclude a list of
words from use as FriendlyId slugs.

With Ruby on Rails, FriendlyId's generator generates an initializer that
reserves some words such as "new" and "edit" using {FriendlyId.defaults
FriendlyId.defaults}.

Note that the error messages for fields will appear on the field
`:friendly_id`. If you are using Rails's scaffolded form errors display, then
it will have no field to highlight. If you'd like to change this so that
scaffolding works as expected, one way to accomplish this is to move the error
message to a different field. For example:

    class Person < ActiveRecord::Base
      extend FriendlyId
      friendly_id :name, use: :slugged

      after_validation :move_friendly_id_error_to_name

      def move_friendly_id_error_to_name
        errors.add :name, *errors.delete(:friendly_id) if errors[:friendly_id].present?
      end
    end

=end
  module Reserved

    # When included, this module adds configuration options to the model class's
    # friendly_id_config.
    def self.included(model_class)
      model_class.class_eval do
        friendly_id_config.class.send :include, Reserved::Configuration
        validates_exclusion_of :friendly_id, :in => ->(_) {
          friendly_id_config.reserved_words || []
        }
      end
    end

    # This module adds the `:reserved_words` configuration option to
    # {FriendlyId::Configuration FriendlyId::Configuration}.
    module Configuration
      attr_accessor :reserved_words
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
friendly_id-5.2.2 lib/friendly_id/reserved.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/friendly_id-5.2.1/lib/friendly_id/reserved.rb
friendly_id-5.2.1 lib/friendly_id/reserved.rb
friendly_id-5.2.0 lib/friendly_id/reserved.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/friendly_id-5.0.5/lib/friendly_id/reserved.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/friendly_id-5.0.5/lib/friendly_id/reserved.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/friendly_id-5.0.5/lib/friendly_id/reserved.rb
friendly_id-5.2.0.beta.1 lib/friendly_id/reserved.rb
friendly_id-5.0.5 lib/friendly_id/reserved.rb
friendly_id-5.1.0 lib/friendly_id/reserved.rb
friendly_id-5.1.0.beta.1 lib/friendly_id/reserved.rb
friendly_id-5.0.4 lib/friendly_id/reserved.rb
friendly_id-5.0.3 lib/friendly_id/reserved.rb
friendly_id-5.0.2 lib/friendly_id/reserved.rb
friendly_id-5.0.1 lib/friendly_id/reserved.rb
friendly_id-5.0.0 lib/friendly_id/reserved.rb
friendly_id-5.0.0.rc3 lib/friendly_id/reserved.rb
friendly_id-5.0.0.rc2 lib/friendly_id/reserved.rb
friendly_id-5.0.0.rc1 lib/friendly_id/reserved.rb