Module: I18nRouting::RackMountRoute

Defined in:
lib/i18n_routing_rails31.rb

Overview

Rack::Mount::Route module Exists in order to use apropriate 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



394
395
396
397
# File 'lib/i18n_routing_rails31.rb', line 394

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

Instance Method Details

#generate_with_i18n_routing(method, params = {}, recall = {}, options = {}) ⇒ Object

Called for dynamic route generation If a @locale is present and if this locale is not the current one

=> return nil and refuse to generate the route


415
416
417
418
# File 'lib/i18n_routing_rails31.rb', line 415

def generate_with_i18n_routing(method, params = {}, recall = {}, options = {})
  return nil if @locale and @locale != I18n.locale.to_sym
  generate_without_i18n_routing(method, params, recall, options)
end

#initialize_with_i18n_routing(app, conditions, defaults, name) ⇒ Object

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



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

def initialize_with_i18n_routing(app, conditions, defaults, name)
  @locale = if conditions.key?(:i18n_locale)
    c = conditions.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(app, conditions, defaults, name)
end