Class: Admin::LocatorsController
- Defined in:
- app/controllers/admin/locators_controller.rb
Instance Method Summary collapse
- #edit ⇒ Object
- #export ⇒ Object
- #import ⇒ Object
- #prepare ⇒ Object
- #reload ⇒ Object
- #update ⇒ Object
Instance Method Details
#edit ⇒ Object
29 30 31 |
# File 'app/controllers/admin/locators_controller.rb', line 29 def edit @locale_hash = YAML.load_file(@file) end |
#export ⇒ Object
7 8 9 10 11 |
# File 'app/controllers/admin/locators_controller.rb', line 7 def export :export, resource_class keys = Locator.export_csv(*params[:keys].to_s.split(','), locales: params[:locales], files: params[:files]) send_data(keys, filename: "locales_#{Time.now.strftime('%Y_%m_%d')}.csv", type: Mime[:csv], disposition: 'attachment') end |
#import ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/admin/locators_controller.rb', line 13 def import if params[:csv_file].present? csv = params[:csv_file].read.force_encoding('UTF-8') errors = Locator.csv_errors(csv) if errors.present? flash[:error] = errors.join('<br/>').html_safe.first(500) else Locator.import_csv(csv, locales: params[:locales]) flash[:notice] = 'File imported' end else flash[:error] = 'Missing or invalid csv file' end redirect_to admin_locators_path end |
#prepare ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/admin/locators_controller.rb', line 43 def prepare result = Locator.instance.prepare_files if !result flash[:error] = 'Failed to prepare locale files' elsif result[:message] flash[:error] = result[:message] else flash[:notice] = I18n.t('flash.admin.locators.prepared') end redirect_to admin_locators_path end |
#reload ⇒ Object
55 56 57 58 59 60 |
# File 'app/controllers/admin/locators_controller.rb', line 55 def reload I18n.reload! Locator.reload_checker.expire if Locator.respond_to?(:reload_checker) flash[:notice] = I18n.t('flash.admin.locators.restart') redirect_to admin_locators_path end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/admin/locators_controller.rb', line 33 def update if Locator.save(@file, {params[:edit_locale_name] => params.require(:locale_hash).permit!.to_h}) flash[:notice] = I18n.t('flash.admin.locators.updated') redirect_to admin_locators_path else flash[:error] = I18n.t('flash.admin.locators.update_error') redirect_to edit_admin_locators_path(filename: params[:filename]) end end |