Class: PhrasingPhrasesController

Inherits:
Object
  • Object
show all
Includes:
PhrasingHelper
Defined in:
app/controllers/phrasing_phrases_controller.rb

Instance Method Summary collapse

Methods included from PhrasingHelper

#can_edit_phrases?

Instance Method Details

#destroyObject



53
54
55
56
57
# File 'app/controllers/phrasing_phrases_controller.rb', line 53

def destroy
  phrasing_phrase = PhrasingPhrase.find(params[:id])
  phrasing_phrase.destroy
  redirect_to phrasing_phrases_path, notice: "#{phrasing_phrase.key} deleted!"
end

#downloadObject



31
32
33
34
35
36
37
# File 'app/controllers/phrasing_phrases_controller.rb', line 31

def download
  app_name = Rails.application.class.to_s.split("::").first
  app_env = Rails.env
  time = Time.now.strftime('%Y_%m_%d_%H_%M_%S')
  filename = "phrasing_phrases_#{app_name}_#{app_env}_#{time}.yml"
  send_data Phrasing::Serializer.export_yaml(phrasing_phrases), filename: filename
end

#editObject



23
24
25
# File 'app/controllers/phrasing_phrases_controller.rb', line 23

def edit
  @phrasing_phrase = PhrasingPhrase.find(params[:id])
end

#helpObject



14
15
# File 'app/controllers/phrasing_phrases_controller.rb', line 14

def help
end

#import_exportObject



11
12
# File 'app/controllers/phrasing_phrases_controller.rb', line 11

def import_export
end

#indexObject



17
18
19
20
21
# File 'app/controllers/phrasing_phrases_controller.rb', line 17

def index
  params[:locale] ||= I18n.default_locale
  @phrasing_phrases = phrasing_phrases
  @locale_names = PhrasingPhrase.distinct.pluck(:locale)
end

#updateObject



27
28
29
# File 'app/controllers/phrasing_phrases_controller.rb', line 27

def update
  request.xhr? ? xhr_phrase_update : phrase_update
end

#uploadObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/phrasing_phrases_controller.rb', line 39

def upload
  number_of_changes = Phrasing::Serializer.import_yaml(params["file"].tempfile)
  redirect_to phrasing_phrases_path, notice: "YAML file uploaded successfully! Number of phrases changed: #{number_of_changes}."
rescue => e
  message = if params[:file].nil?
              'Please choose a file.'
            else
              'Please upload a valid YAML file.'
            end

  flash[:alert] = "There was an error processing your upload! #{message}"
  render action: 'import_export', status: 400
end