Module: FriendlyId::Scoped::SlugGenerator

Defined in:
lib/friendly_id/scoped.rb

Overview

This module overrides FriendlyId::SlugGenerator#conflict to consider scope, to avoid adding sequences to slugs under different scopes.

Instance Method Summary (collapse)

Instance Method Details

- (Object) conflict (private)



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/friendly_id/scoped.rb', line 164

def conflict
  if friendly_id_config.uses?(:history)
    # When using the :history module +conflicts+ already returns only real conflicts, so there's no need to check
    # for the scope columns again
    conflicts.first
  else
    columns = friendly_id_config.scope_columns
    matched = columns.inject(conflicts) do |memo, column|
      memo.where(column => sluggable.send(column))
    end

    matched.first
  end
end