Class: Aspartame::AspartameTranslationsController

Inherits:
ApplicationController show all
Includes:
AspartameSessionsHelper
Defined in:
app/controllers/aspartame/aspartame_translations_controller.rb

Instance Method Summary collapse

Methods included from AspartameSessionsHelper

#aspartame_current_user, #aspartame_current_user=, #aspartame_current_user?, #aspartame_redirect_back_or, #aspartame_sign_in, #aspartame_sign_out, #aspartame_signed_in?, #aspartame_signed_in_user, #aspartame_store_location

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 14

def create
  @aspartame_translation = Aspartame::AspartameTranslation.new(params[:aspartame_translation])
  if @aspartame_translation.save
    respond_to do |format|
      format.html { redirect_to refinery.root_path } # create.html.erb
      format.js
    end
  end
end

#destroyObject



24
25
26
27
28
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 24

def destroy
  Aspartame::AspartameTranslation.find(params[:id]).destroy
  flash[:success] = "Translation destroyed."
  redirect_to aspartame.aspartame_translations_path
end

#editObject



30
31
32
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 30

def edit
  @aspartame_translation = Aspartame::AspartameTranslation.find(params[:id])
end

#edit_multipleObject



75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 75

def edit_multiple
	@aspartame_translations = Aspartame::AspartameTranslation.find(params[:aspartame_translation_ids])
	# add secondary controller action for delete button
	if params[:commit] == "Delete"
 	@aspartame_translations.each do |translation|
 		translation.destroy
 	end
 	flash[:success] = "Translations destroyed!"
  redirect_to aspartame.aspartame_translations_path	
	end
end

#indexObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 47

def index
 if defined?(params[:language][:language]).nil?
  @params_language = nil
  @select_language = "All"
elsif params[:language][:language] == "All"
  	@params_language = nil
  	@select_language = "All"
  else
@params_language = params[:language]
@select_language = params[:language][:language]
			end
			if defined?(params[:url][:url]).nil?
@params_url = nil
@select_url = "All"
			elsif params[:url][:url] == "All"
   @params_url = nil
   @select_url = "All"
 else
   @params_url = params[:url]
   @select_url = params[:url][:url]
 end
 @aspartame_translations = Aspartame::AspartameTranslation.where(@params_language).where(@params_url).paginate(page: params[:page])
end

#newObject



10
11
12
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 10

def new
  @aspartame_translation = Aspartame::AspartameTranslation.new
end

#showObject



71
72
73
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 71

def show
  @aspartame_translation = Aspartame::AspartameTranslation.find(params[:id])
end

#toggleObject



96
97
98
99
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 96

def toggle
  @aspartame_translation = Aspartame::AspartameTranslation.find(params[:id])
  @aspartame_translation.toggle!(:status)
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 34

def update
  if @aspartame_translation.update_attributes(params[:aspartame_translation])
    flash[:success] = "Translation updated."
    respond_to do |format|
    	format.html { redirect_to aspartame.aspartame_translations_path }
    	format.js
    end
  else
    flash[:error] = "Update failure."
    render 'edit'
  end  
end

#update_multipleObject



87
88
89
90
91
92
93
94
# File 'app/controllers/aspartame/aspartame_translations_controller.rb', line 87

def update_multiple
	@aspartame_translations = Aspartame::AspartameTranslation.find(params[:aspartame_translation_ids])
	@aspartame_translations.each do |translation|
		translation.update_attributes!(params[:aspartame_translation].reject {|k,v| v.blank?})
	end
	flash[:success] = "Translations updated!"
	redirect_to aspartame.aspartame_translations_path
end