Class: WidgetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/widgets_controller.rb

Overview

typed: false

Instance Method Summary collapse

Methods inherited from ApplicationController

#gdpr_compliance

Instance Method Details

#createObject

POST /widgets POST /widgets.json



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/widgets_controller.rb', line 35

def create
  @widget = Widget.new(widget_params)

  respond_to do |format|
    if @widget.save
      format.html { redirect_to @widget, notice: 'Widget was successfully created.' }
      format.json { render :show, status: :created, location: @widget }
    else
      format.html { render :new }
      format.json { render json: @widget.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /widgets/1 DELETE /widgets/1.json



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

def destroy
  @widget.destroy
  respond_to do |format|
    format.html { redirect_to widgets_url, notice: 'Widget was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /widgets/1/edit



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

def edit
end

#indexObject

GET /widgets GET /widgets.json



7
8
9
# File 'app/controllers/widgets_controller.rb', line 7

def index
  @widgets = Widget.all
end

#newObject

GET /widgets/new



25
26
27
# File 'app/controllers/widgets_controller.rb', line 25

def new
  @widget = Widget.new
end

#showObject

GET /widgets/1 GET /widgets/1.json



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/widgets_controller.rb', line 13

def show
  respond_to do |format|
    format.html do
      render 'show'
    end
    format.wasm do
      render 'show'
    end
  end
end

#updateObject

PATCH/PUT /widgets/1 PATCH/PUT /widgets/1.json



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/widgets_controller.rb', line 51

def update
  respond_to do |format|
    if @widget.update(widget_params)
      format.html { redirect_to @widget, notice: 'Widget was successfully updated.' }
      format.json { render :show, status: :ok, location: @widget }
    else
      format.html { render :edit }
      format.json { render json: @widget.errors, status: :unprocessable_entity }
    end
  end
end