Class: Flexite::EntriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/flexite/entries_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/flexite/entries_controller.rb', line 12

def create
  result = call_service_for(:create, entry_params)

  if result.succeed?
    @entry = result.record
    @entry_form = @entry.class.form(@entry.form_attributes)
  end

  service_flash(result)
  service_response(result)
end

#destroyObject



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/flexite/entries_controller.rb', line 63

def destroy
  result = call_service_for(:destroy, params)

  if result.succeed?
    @parent_id = result.data[:parent_id]
  end

  service_flash(result)
  service_response(result)
end

#destroy_array_entryObject



56
57
58
59
60
61
# File 'app/controllers/flexite/entries_controller.rb', line 56

def destroy_array_entry
  result = ServiceFactory.instance.get(:destroy_array_entry, Entry.form(params)).call
  @selector = params[:selector]
  service_flash(result)
  service_response(result)
end

#editObject



24
25
26
27
# File 'app/controllers/flexite/entries_controller.rb', line 24

def edit
  @entry = Entry.find(params[:id])
  @entry_form = @entry.class.form(@entry.form_attributes)
end

#newObject



7
8
9
10
# File 'app/controllers/flexite/entries_controller.rb', line 7

def new
  klass = entry_params[:type].constantize
  @entry_form = klass.form(entry_params)
end

#new_array_entryObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/flexite/entries_controller.rb', line 41

def new_array_entry
  klass = params[:type].constantize

  @prefix = params[:prefix]
  @form_options = [@prefix]

  if (@form_index = params[:form_index]).present?
    @form_options << { index: @form_index }
  end

  @parent_id = params[:parent_id]
  @index = params[:index]
  @entry_form = klass.form(klass.new.form_attributes)
end

#select_typeObject



74
75
76
# File 'app/controllers/flexite/entries_controller.rb', line 74

def select_type
  @config = Config.find(params[:parent_id])
end

#updateObject



29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/flexite/entries_controller.rb', line 29

def update
  result = call_service_for(:update, entry_params)

  if result.succeed?
    @entry = Entry.find(entry_params[:id])
    @entry_form = @entry.class.form(@entry.form_attributes)
  end

  service_flash(result)
  service_response(result)
end