Class: CrujCrujCrujController

Inherits:
ApplicationController
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper
Defined in:
app/controllers/cruj_cruj_cruj_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 25

def create
  if @resource.save
    redirect_to(action: :index, notice: l("#{snake_case_model_name}_create_success_message"))
  else
    render action: 'new'
  end
end

#destroyObject



45
46
47
48
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 45

def destroy
  @resource.destroy
  redirect_to action: :index, notice: l("#{snake_case_model_name}_delete_success_message")
end

#editObject



33
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 33

def edit; end

#export_templateObject



50
51
52
53
54
55
56
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 50

def export_template
  @q = model_class.ransack(params[:q])
  @q.sorts = default_sort if @q.sorts.blank?

  filename = CrujCrujCruj::Services::ImportRules.export_template(form_fields, @q.result)
  send_file(filename, filename: l(:export_template_filename), type: "application/vnd.ms-excel")
end

#importObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 58

def import
  if params[:file].blank?
    redirect_to url_for(action: :index, controller: params[:controller]), {flash: {error: l(:no_file_to_import_error_message)}}
    return
  end

  errors = CrujCrujCruj::Services::ImportRules.import(params[:file], form_fields, model_class)

  if errors.blank?
    redirect_to url_for(action: :index, controller: params[:controller]), notice: l(:import_success_message)
    return
  end
  redirect_to url_for(action: :index, controller: params[:controller]), flash: { import_errors: errors.join('<br />') }
end

#indexObject



22
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 22

def index; end

#newObject



23
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 23

def new; end

#updateObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/cruj_cruj_cruj_controller.rb', line 35

def update
  if @resource.update_attributes(safe_parameters)
    redirect_to(action: :index, notice: l("#{snake_case_model_name}_edit_success_message"))
  else
    render action: 'edit'
  end
rescue ActiveRecord::RecordNotFound
  render_404
end