Class: Fae::NestedBaseController

Inherits:
ApplicationController show all
Defined in:
app/controllers/fae/nested_base_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/fae/nested_base_controller.rb', line 23

def create
  @item = @klass.new(permitted_params)
  raise_undefined_parent if @item.fae_nested_parent.blank?

  if @item.save
    @parent_item = @item.send(nested_parent)
    flash[:notice] = t('fae.save_notice')
    render template: table_template_path
  else
    build_assets
    render action: 'new'
  end
end

#destroyObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/fae/nested_base_controller.rb', line 50

def destroy
  raise_undefined_parent if @item.fae_nested_parent.blank?
  @parent_item = @item.send(nested_parent)

  if @item.destroy
    flash[:notice] = t('fae.delete_notice')
  else
    flash[:alert] = t('fae.delete_error')
  end
  render template: table_template_path
end

#editObject



19
20
21
# File 'app/controllers/fae/nested_base_controller.rb', line 19

def edit
  build_assets
end

#newObject



10
11
12
13
14
15
16
17
# File 'app/controllers/fae/nested_base_controller.rb', line 10

def new
  @item = @klass.new
  raise_undefined_parent if @item.fae_nested_foreign_key.blank?

  item_id = params[:item_id].to_i || nil
  @item.send("#{parent_foreign_key}=", item_id)
  build_assets
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/fae/nested_base_controller.rb', line 37

def update
  raise_undefined_parent if @item.fae_nested_parent.blank?

  if @item.update(permitted_params)
    @parent_item = @item.send(nested_parent)
    flash[:notice] = t('fae.save_notice')
    render template: table_template_path
  else
    build_assets
    render action: 'edit'
  end
end