class MagicLocales::LocalesController

Public Instance Methods

change_locale() click to toggle source
# 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
create() click to toggle source
# 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
edit() click to toggle source
# File lib/app/controllers/magic_locales/locales_controller.rb, line 25
def edit
  @locale = MagicLocales::Locale.find(params[:id])
  render :form
end
index() click to toggle source
# 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
new() click to toggle source
# File lib/app/controllers/magic_locales/locales_controller.rb, line 11
def new
  @locale = MagicLocales::Locale.new()
  render :form
end
trigger() click to toggle source
# 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
update() click to toggle source
# 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

Private Instance Methods

locale_params() click to toggle source

Never trust parameters from the scary internet, only allow the white list through.

# File lib/app/controllers/magic_locales/locales_controller.rb, line 57
def locale_params
  params.require(:magic_locales_locale).permit(:name, :natural_name, :iso_code, :translations_attributes => [:id, :name, :locale])
end