Module: I18nRouting::JourneyRoute

Defined in:
lib/i18n_routing_rails32.rb

Overview

Journey::Route module Exists in order to use appropriate localized route when using url_for

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

Alias methods in order to handle i18n routes



393
394
395
396
# File 'lib/i18n_routing_rails32.rb', line 393

def self.included(mod)
  mod.send :alias_method_chain, :initialize, :i18n_routing
  mod.send :alias_method_chain, :score, :i18n_routing
end

Instance Method Details

#initialize_with_i18n_routing(name, app, path, constraints, defaults = {}) ⇒ Object

During route initialization, if a condition i18n_locale is present Delete it, store it in @locale, and add it to @defaults



400
401
402
403
404
405
406
407
408
409
# File 'lib/i18n_routing_rails32.rb', line 400

def initialize_with_i18n_routing(name, app, path, constraints, defaults = {})
  @locale = if constraints.key?(:i18n_locale)
    c = constraints.delete(:i18n_locale)
    # In rails 3.0 it's a regexp otherwise it's a string, so we need to call source on the regexp
    (c.respond_to?(:source) ? c.source : c).to_sym
  else
    nil
  end
  initialize_without_i18n_routing(name, app, path, constraints, defaults)
end

#score_with_i18n_routing(constraints) ⇒ Object

Return low score for routes that don’t match the current locale



412
413
414
415
# File 'lib/i18n_routing_rails32.rb', line 412

def score_with_i18n_routing constraints
  return -1 if @locale && @locale != I18n.locale.to_sym
  score_without_i18n_routing constraints
end