Module: AuxiliaryRails::Concerns::Resourceable

Extended by:
ActiveSupport::Concern
Includes:
Pagy::Backend, Pundit::Authorization
Defined in:
lib/auxiliary_rails/concerns/resourceable.rb

Overview

Resourceable - concern for controllers

Instance Method Summary collapse

Instance Method Details

#createObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 41

def create
  self.resource = build_resource(resource_params)

  if resource.save
    respond_to do |format|
      format.html { redirect_after_create }
      format.json
    end
  else
    render :new
  end
end

#destroyObject



73
74
75
76
77
78
79
80
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 73

def destroy
  resource.destroy

  respond_to do |format|
    format.html { redirect_after_destroy }
    format.json
  end
end

#editObject



57
58
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 57

def edit
end

#indexObject



26
27
28
29
30
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 26

def index
  @ransack = collection.ransack(search_params)
  @ransack.sorts = default_sorts if @ransack.sorts.empty?
  @pagy, self.collection = pagy(@ransack.result)
end

#newObject



32
33
34
35
36
37
38
39
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 32

def new
  self.resource =
    if params.key?(resource_name)
      build_resource(resource_params)
    else
      build_resource
    end
end

#showObject



54
55
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 54

def show
end

#updateObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/auxiliary_rails/concerns/resourceable.rb', line 60

def update
  resource.assign_attributes(resource_params)

  if resource.save
    respond_to do |format|
      format.html { redirect_after_update }
      format.json
    end
  else
    render :edit
  end
end