Class: MagicLocales::LocalesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- MagicLocales::LocalesController
- Defined in:
- lib/app/controllers/magic_locales/locales_controller.rb
Instance Method Summary collapse
- #change_locale ⇒ Object
- #create ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #trigger ⇒ Object
- #update ⇒ Object
Instance Method Details
#change_locale ⇒ Object
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 |
#create ⇒ Object
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..join(" ")}" end end |
#edit ⇒ Object
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 |
#index ⇒ Object
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 |
#new ⇒ Object
11 12 13 14 |
# File 'lib/app/controllers/magic_locales/locales_controller.rb', line 11 def new @locale = MagicLocales::Locale.new() render :form end |
#trigger ⇒ Object
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 |
#update ⇒ Object
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..join(" ")}" end end |