Class: RailsI18nOnair::TranslationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RailsI18nOnair::TranslationsController
- Defined in:
- app/controllers/rails_i18n_onair/translations_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 21 def create @translation = RailsI18nOnair::Translation.new(translation_params) if @translation.save # Invalidate cache for the newly created locale reload_backend_locale(@translation.language) redirect_to translations_path, notice: "Translation for #{@translation.language} created successfully" else flash.now[:alert] = "Failed to create translation" render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 67 def destroy language = @translation.language if @translation.destroy # Invalidate cache for the deleted locale reload_backend_locale(language) redirect_to translations_path, notice: "Translation for #{language} deleted successfully" else redirect_to translations_path, alert: "Failed to delete translation" end end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 35 def edit @parsed_data = @translation.translation || {} end |
#index ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 5 def index @translations = RailsI18nOnair::Translation.order(:language) if params[:search].present? @translations = @translations.where("language ILIKE ?", "%#{params[:search]}%") end end |
#new ⇒ Object
17 18 19 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 17 def new @translation = RailsI18nOnair::Translation.new end |
#show ⇒ Object
13 14 15 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 13 def show @parsed_data = @translation.translation || {} end |
#update ⇒ Object
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 65 |
# File 'app/controllers/rails_i18n_onair/translations_controller.rb', line 39 def update # Convert nested form params back to hash new_translation_data = reconstruct_hash_from_params(params[:translations] || {}) if new_translation_data.empty? flash.now[:alert] = "No translation data received. Please ensure all fields are filled." @parsed_data = @translation.translation || {} render :edit, status: :unprocessable_entity return end if @translation.update(translation: new_translation_data) # Invalidate only the updated locale's cache reload_backend_locale(@translation.language) redirect_to translation_path(@translation), notice: "Translation updated successfully" else flash.now[:alert] = "Failed to update translation" @parsed_data = new_translation_data render :edit, status: :unprocessable_entity end rescue StandardError => e flash.now[:alert] = "Error processing translations: #{e.}" @parsed_data = @translation.translation || {} raise e if Rails.env.development? # Re-raise in development for debugging render :edit, status: :unprocessable_entity end |