Class: MagicLocales::LocalesController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/app/controllers/magic_locales/locales_controller.rb

Instance Method Summary collapse

Instance Method Details

#change_localeObject



45
46
47
48
49
50
51
52
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 45

def change_locale
  if I18n.available_locales.include?( params[:locale].to_sym )
    session[:user_locale] = params[:locale]
    session[:locale] = params[:locale]
    I18n.locale = params[:locale]
  end
  redirect_to url_for( Rails.application.routes.recognize_path( params[:back] ).merge({locale: params[:locale]}) ), notice: I18n.t("messages.locale_changed", locale: params[:locale])
end

#createObject



16
17
18
19
20
21
22
23
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 16

def create
  @locale = MagicLocales::Locale.new(locale_params)
  if @locale.save
    redirect_to action: :index, notice: "Saved locale"
  else
    redirect_to action: :index, alert: "Error! #{@locale.errors.full_messages.join(" ")}"
  end
end

#editObject



25
26
27
28
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 25

def edit
  @locale = MagicLocales::Locale.find(params[:id])
  render :form
end

#indexObject



4
5
6
7
8
9
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 4

def index
  # => @locales = ::MagicLocales::Locale.includes(:translations).with_translations(I18n.locale).order( 'mgclang_locale_translations.name ASC' )
  @locales = MagicLocales::Locale.where(locale_state: "live").includes(:translations).with_translations(I18n.locale).order( 'mgclang_locale_translations.name ASC' )
  @locales += MagicLocales::Locale.where(locale_state: "active").includes(:translations).with_translations(I18n.locale).order( 'mgclang_locale_translations.name ASC' )
  @locales += MagicLocales::Locale.where(locale_state: "inactive").includes(:translations).with_translations(I18n.locale).order( 'mgclang_locale_translations.name ASC' )
end

#newObject



11
12
13
14
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 11

def new
  @locale = MagicLocales::Locale.new()
  render :form
end

#triggerObject



39
40
41
42
43
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 39

def trigger
  @locale = MagicLocales::Locale.find( params[:id] )
  @locale.do_transition!( params[:state].to_sym )
  redirect_to action: :index
end

#updateObject



30
31
32
33
34
35
36
37
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 30

def update
  @locale = MagicLocales::Locale.find(params[:id])
  if @locale.update(locale_params)
    redirect_to action: :index, notice: "Saved locale"
  else
    redirect_to action: :index, alert: "Error! #{@locale.errors.full_messages.join(" ")}"
  end
end