module FriendlyId::Scoped::Configuration

This module adds the `:scope` configuration option to {FriendlyId::Configuration FriendlyId::Configuration}.

Attributes

scope[RW]

Gets the scope value.

When setting this value, the argument should be a symbol referencing a `belongs_to` relation, or a column.

@return Symbol The scope value

Public Instance Methods

scope_columns() click to toggle source

Gets the scope columns.

Checks to see if the `:scope` option passed to {FriendlyId::Base#friendly_id} refers to a relation, and if so, returns the realtion's foreign key. Otherwise it assumes the option value was the name of column and returns it cast to a String.

@return String The scope column

# File lib/friendly_id/scoped.rb, line 163
def scope_columns
  [@scope].flatten.map { |s| (reflection_foreign_key(s) or s).to_s }
end

Private Instance Methods

reflection_foreign_key(scope) click to toggle source
# File lib/friendly_id/scoped.rb, line 169
def reflection_foreign_key(scope)
  reflection = model_class.reflections[scope] || model_class.reflections[scope.to_s]
  reflection.try(:foreign_key)
end