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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 34

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/create_belongs_to', locals: { resource: @resource_instance }
        else
          # we are in other controller as a has_many, add checkbox
          render 'adminpanel/templates/create_has_many', locals: { resource: @resource_instance }
        end
      end
    else
      render_new(format)
    end
  end
end

#destroyObject



69
70
71
72
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 69

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

#editObject



57
58
59
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 57

def edit
  render 'adminpanel/templates/edit'
end

#indexObject



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

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

#newObject



27
28
29
30
31
32
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 27

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

#showObject



23
24
25
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 23

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

#updateObject



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

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