blob: cea2adc5e48799f443e57a037f0005bfe01e9440 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
class MachinesController < ApplicationController
def random
@machine = Machine.order(Arel.sql("RANDOM()")).first
render :show
end
def index
@machines = Machine.order("name")
end
def show
@machine = Machine.find(params[:id])
end
def new
@machine = Machine.new
end
def create
@machine = Machine.new(machine_params)
if @machine.save
redirect_to machines_path
else
render :new
end
end
def edit
@machine = Machine.find(params[:id])
end
def update
@machine = Machine.find(params[:id])
if @machine.update(machine_params)
redirect_to machines_path
else
render :edit
end
end
def destroy
@machine = Machine.find(params[:id])
@machine.destroy
redirect_to machines_path
end
private
def machine_params
params.require(:machine).permit(:name, :edition)
end
end
|