Module: FriendlyId::Scoped::Configuration
- Defined in:
- lib/friendly_id/scoped.rb
Overview
This module adds the :scope
configuration option to
FriendlyId::Configuration.
Instance Attribute Summary (collapse)
-
- (Object) scope
Gets the scope value.
Instance Method Summary (collapse)
- - (Object) reflection_foreign_key(scope) private
-
- (Object) scope_columns
Gets the scope columns.
Instance Attribute Details
- (Object) scope
Gets the scope value.
When setting this value, the argument should be a symbol referencing a
belongs_to
relation, or a column.
149 150 151 |
# File 'lib/friendly_id/scoped.rb', line 149 def scope @scope end |
Instance Method Details
- (Object) reflection_foreign_key(scope) (private)
165 166 167 |
# File 'lib/friendly_id/scoped.rb', line 165 def reflection_foreign_key(scope) model_class.reflections[scope].try(:foreign_key) end |
- (Object) scope_columns
Gets the scope columns.
Checks to see if the :scope
option passed to
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.
159 160 161 |
# File 'lib/friendly_id/scoped.rb', line 159 def scope_columns [@scope].flatten.map { |s| (reflection_foreign_key(s) or s).to_s } end |