Class: CopycatTranslationsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- CopycatTranslationsController
- Defined in:
- app/controllers/copycat_translations_controller.rb
Instance Method Summary collapse
- #destroy ⇒ Object
- #download ⇒ Object
- #edit ⇒ Object
- #help ⇒ Object
- #import_export ⇒ Object
- #index ⇒ Object
- #update ⇒ Object
- #upload ⇒ Object
Instance Method Details
#destroy ⇒ Object
57 58 59 60 61 62 |
# File 'app/controllers/copycat_translations_controller.rb', line 57 def destroy @copycat_translation = CopycatTranslation.find(params[:id]) notice = "#{@copycat_translation.key} deleted!" @copycat_translation.destroy redirect_to copycat_translations_path, :notice => notice end |
#download ⇒ Object
40 41 42 43 |
# File 'app/controllers/copycat_translations_controller.rb', line 40 def download filename = "copycat_translations_#{Time.now.strftime("%Y_%m_%d_%H_%M_%S")}.yml" send_data CopycatTranslation.export_yaml, :filename => filename end |
#edit ⇒ Object
26 27 28 |
# File 'app/controllers/copycat_translations_controller.rb', line 26 def edit @copycat_translation = CopycatTranslation.find(params[:id]) end |
#help ⇒ Object
64 65 |
# File 'app/controllers/copycat_translations_controller.rb', line 64 def help end |
#import_export ⇒ Object
37 38 |
# File 'app/controllers/copycat_translations_controller.rb', line 37 def import_export end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/copycat_translations_controller.rb', line 7 def index params[:locale] = I18n.default_locale unless params.has_key?(:locale) query = CopycatTranslation query = query.where(locale: params[:locale]) unless params[:locale].blank? if params.has_key?(:search) if params[:search].blank? @copycat_translations = query.all else key_like = CopycatTranslation.arel_table[:key].matches("%#{params[:search]}%") value_like = CopycatTranslation.arel_table[:value].matches("%#{params[:search]}%") @copycat_translations = query.where(key_like.or(value_like)) end else @copycat_translations = [] end @locale_names = CopycatTranslation.find(:all, select: 'distinct locale').map(&:locale) end |
#update ⇒ Object
30 31 32 33 34 35 |
# File 'app/controllers/copycat_translations_controller.rb', line 30 def update @copycat_translation = CopycatTranslation.find(params[:id]) @copycat_translation.value = params[:copycat_translation][:value] @copycat_translation.save! redirect_to copycat_translations_path, :notice => "#{@copycat_translation.key} updated!" end |
#upload ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/copycat_translations_controller.rb', line 45 def upload begin CopycatTranslation.import_yaml(params["file"].tempfile) rescue Exception => e logger.info "\n#{e.class}\n#{e.}" flash[:notice] = "There was an error processing your upload!" render :action => 'import_export', :status => 400 else redirect_to copycat_translations_path, :notice => "YAML file uploaded successfully!" end end |