Module: TranslationsControllerHelpers

Defined in:
lib/translations_controller_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
# File 'lib/translations_controller_helpers.rb', line 3

def self.included(klass)
  klass.send :helper_method, :url_for_translated, :target_action, :target_locale
end

Instance Method Details

#target_action(options = {}) ⇒ Object



17
18
19
# File 'lib/translations_controller_helpers.rb', line 17

def target_action(options = {})
  options.delete(:action) || 'show'
end

#target_controller(options = {}) ⇒ Object



12
13
14
15
# File 'lib/translations_controller_helpers.rb', line 12

def target_controller(options = {})
  translatable_params_name = options.delete(:translatable_params_name) || @translatable_params_name
  options.delete(:controller) || translatable_params_name.pluralize || params[:controller]
end

#target_id(options = {}) ⇒ Object



21
22
23
24
# File 'lib/translations_controller_helpers.rb', line 21

def target_id(options = {})
  translated = options.delete(:translated) || @translated || options.delete(:translatable) || @translatable
  options.delete(:id) || translated
end

#target_locale(options = {}) ⇒ Object



7
8
9
10
# File 'lib/translations_controller_helpers.rb', line 7

def target_locale(options = {})
  translation = options.delete(:translation) || @translation
  options.delete(:locale) || (translation.locale if translation) || I18n.locale
end

#url_for_translated(options = { }) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/translations_controller_helpers.rb', line 26

def url_for_translated(options = { })
  defaults = {
    :locale => target_locale(options),
    :controller => target_controller(options),
    :action => target_action(options),
    :id => target_id(options)
  }

  url_for(defaults.merge(options))
end