Class: Kakimasu::KeysController

Inherits:
ApplicationController
  • Object
show all
Includes:
GroupingHelper, PaginationHelper, SearchKeyHelper, SearchTranslationsHelper
Defined in:
app/controllers/kakimasu/keys_controller.rb

Instance Method Summary collapse

Methods included from PaginationHelper

#get_page_size, #set_page_size, #total_pages

Methods included from SearchKeyHelper

#lazy_lookup_key, #remove_lazy_lookup

Methods included from GroupingHelper

#get_translation_key_paths, #group_by_language

Methods included from SearchTranslationsHelper

#find_attribute_keys, #find_keys, #find_missing_translations_keys, #find_model_name_keys, #missing_translations?, #prefix, #search_for_translations

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/kakimasu/keys_controller.rb', line 23

def create
  # Authorize user
  authorize :translation, :create?

  before_key = params[:key]     # Varibale contains key before create method was executed

  # Check if path to translation key is given
  enable_lazy_lookup unless params[:path].blank?

  # Variable which is true when function saves changes of something.
  changed = false

  # Save entered translations
  I18n.available_locales.each do |l|
    params[l].gsub!("'", "'")     # Substitutes quotes with quotes HTML code.

    # If there is translation which is not equal with old one, then it is saved
    unless params[l].blank? || I18n.t(params[:key], locale: l) == params[l]
      changed = true if (I18n.backend.store_translations(l, { params[:key] => params[l] }, escape: false))
    end
  end
  I18n.backend.store_translations(params[:language], { params[:key] => params[:value] }, escape: false) if params[:language]

  # Process ajax process diferently
  if request.xhr?
    respond_to do |format|
      format.js {}
    end
  else
    redirect_to kakimasu_keys_path(keys_category: @category)
  end

  # If the key is changed then it means there were changes
  changed = true if before_key != params[:key]

  # Shows result to user
  if changed
    flash.notice = t('translation_succesfully_stored')
  else
    flash.alert = t('nothing_was_changed')
  end
end

#indexObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/kakimasu/keys_controller.rb', line 12

def index
  # Check if user has permissions
  authorize :translation, :index?
  policy_scope(Translation)

  set_page_size(5)                              # set number of keys in one page
  params[:page] = 1 unless params[:page]        # if page number is not stated, then by default it is 1. page
  @keys = search_for_translations(@category)    # search for used keys
  @active_tab = 'keys'                          # sets active tab in navigation
end