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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 42

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
      format.html do
        render 'adminpanel/templates/new'
      end
      format.js do
        render 'adminpanel/templates/new'
      end
    end
  end
end

#destroyObject



82
83
84
85
86
87
88
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 82

def destroy
  @resource_instance.destroy
  respond_to do |format|
    format.html { redirect_to action: :index }
    format.js { render('adminpanel/templates/destroy') }
  end
end

#editObject



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

def edit
  render 'adminpanel/templates/edit'
end

#indexObject



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

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

#newObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 30

def new
  @resource_instance = @model.new
  respond_to do |format|
    format.html do
      render 'adminpanel/templates/new'
    end
    format.js do
      render 'adminpanel/templates/new'
    end
  end
end

#showObject



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

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

#updateObject



74
75
76
77
78
79
80
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 74

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