-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsample.rb
53 lines (37 loc) · 930 Bytes
/
sample.rb
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
class ProductsController < ApplicationController
respond_to :html # Set in the ApplicationController
before_filter :admin_user!
before_action :set_product, only: [:edit, :update, :destroy]
def index
@products = Product.order :name
respond_with @products
end
def new
@product = Product.new
respond_with @product
end
def edit; end
def create
@product = Product.new product_params
@product.save
respond_with @product, location: products_path
end
def update
@product.update product_params
respond_with @product, location: products_path
end
def destroy
@product.destroy
respond_with @product, location: products_path
end
private
def set_product
@product = Product.find params[:id]
end
def product_params
params.require(:product).permit :name, :kind
end
def admin_user!
raise MyCustomError if !current_user.admin?
end
end