Class: Api::AttributesController

Inherits:
ApiController
  • Object
show all
Defined in:
app/controllers/api/attributes_controller.rb

Instance Method Summary collapse

Methods inherited from ApiController

#current_user

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/api/attributes_controller.rb', line 27

def create
    render nothing: true, status: 400 unless params[:attribute]
    attribute = BillyCms::AdditionalAttribute.new attributes_params
    if attribute.save
        render json: {
            success: true,
            attribute: attribute
        }
    else
        render json: {
            success: false,
            error: attribute.errors.full_messages.join('. '),
        }, status: 500
    end
end

#destroyObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/api/attributes_controller.rb', line 43

def destroy
    render :nothing, status: 400 unless params[:id]
    if BillyCms::AdditionalAttribute.delete(params[:id])
        render json: {
            success: true
        }
    else
        render json: {
            success: false,
            error: attribute.error_messages,
        }, status: 500
    end
end

#indexObject



3
4
5
# File 'app/controllers/api/attributes_controller.rb', line 3

def index
    render json: BillyCms::AdditionalAttribute.all
end

#showObject



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

def show
    render json: BillyCms::AdditionalAttribute.find(params[:id])
end

#updateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/api/attributes_controller.rb', line 11

def update
    render nothing: true, status: 400 unless params[:attribute]
    attribute = BillyCms::AdditionalAttribute.find params[:id]
    if attribute.update_attributes attributes_params
        render json: {
            success: true,
            attribute: attribute
        }
    else
        render json: {
            success: false,
            error: attribute.error_messages,
        }, status: 500
    end
end