Module: Adminpanel::RestActions

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/concerns/adminpanel/rest_actions.rb

Instance Method Summary collapse

Instance Method Details

#createObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 38

def create
  merge_params
  @resource_instance = @model.new(send(whitelisted_params))
  respond_to do |format|
    if @resource_instance.save
      format.html { redirect_to @resource_instance }
      format.js do
        # if format js, request is from another controller's form
        if params[:belongs_request]
          # we are in other controller as a belongs_to, add option to select
          render 'adminpanel/templates/option_for_select'
        else
          # we are in other controller as a has_many, add checkbox
          render 'adminpanel/templates/checkbox'
        end
      end
    else
      render_new(format)
    end
  end
end

#destroyObject



73
74
75
76
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 73

def destroy
  @resource_instance.destroy
  redirect_to action: :index
end

#editObject



61
62
63
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 61

def edit
  render 'adminpanel/templates/edit'
end

#indexObject



19
20
21
22
23
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 19

def index
  if stale?(etag: @collection, public: true, template: false)
    render 'adminpanel/templates/index'
  end
end

#newObject



31
32
33
34
35
36
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 31

def new
  @resource_instance = @model.new
  respond_to do |format|
    render_new(format)
  end
end

#showObject



25
26
27
28
29
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 25

def show
  if stale?(etag: @resource_instance, public: true, template: false)
    render 'adminpanel/templates/show'
  end
end

#updateObject



65
66
67
68
69
70
71
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 65

def update
  if @resource_instance.update(send(whitelisted_params))
    redirect_to @resource_instance
  else
    render 'adminpanel/templates/edit'
  end
end