Class: RowsController

Inherits:
ApplicationController
  • Object
show all
Includes:
Rows::Model, Rows::Resources, Rows::Utils
Defined in:
app/controllers/rows_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rows::Utils

#resource_format

Methods included from Rows::Resources

#resource, #resources, #set_resource, #set_resources

Methods included from Rows::Model

#model_class, #model_name, #model_symbol, #model_symbol_plural

Class Method Details

.model_class(model_class = nil) ⇒ Object



19
20
21
22
23
24
# File 'app/controllers/rows_controller.rb', line 19

def self.model_class(model_class = nil)
  return @_model_class if model_class.nil?

  @_model_class = model_class
  @_model_class = model_class.constantize if model_class.is_a?(String)
end

Instance Method Details

#createObject



40
41
42
43
44
45
46
47
48
# File 'app/controllers/rows_controller.rb', line 40

def create
  set_resource model_class.new(resource_params)
  msg = t("ui.created", model: model_name)
  if resource.save
    succeded msg, :create
  else
    failed :edit
  end
end

#destroyObject



59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/rows_controller.rb', line 59

def destroy
  resource.destroy
  msg = t("ui.destroyed", model: model_name)
  flash[:notice] = msg unless request.xhr?
  respond_to do |format|
    format.html { redirect_to action: :index }
    format.json { head :no_content }
    # format.turbo_stream {} # outcomment for backward compatibility
  end
end

#editObject



37
38
# File 'app/controllers/rows_controller.rb', line 37

def edit
end

#indexObject



26
27
28
# File 'app/controllers/rows_controller.rb', line 26

def index
  set_resources model_class.all
end

#newObject



33
34
35
# File 'app/controllers/rows_controller.rb', line 33

def new
  set_resource model_class.new
end

#showObject



30
31
# File 'app/controllers/rows_controller.rb', line 30

def show
end

#updateObject



50
51
52
53
54
55
56
57
# File 'app/controllers/rows_controller.rb', line 50

def update
  msg = t("ui.updated", model: model_name)
  if resource.update(resource_params)
    succeded msg, :ok
  else
    failed :edit
  end
end