Class: BillyCms::Api::PagesController

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

Instance Method Summary collapse

Methods inherited from ApiController

#current_user

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/billy_cms/api/pages_controller.rb', line 24

def create
    render nothing: true, status: 400 unless params[:page]
    page = Page.new page_params
    if page.save
        render json: {
            success: true,
            page: page
        }
    else
        render json: {
            success: false,
            error: page.error_messages,
        }, status: 500
    end
end

#destroyObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/billy_cms/api/pages_controller.rb', line 40

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

#indexObject



4
5
6
# File 'app/controllers/billy_cms/api/pages_controller.rb', line 4

def index
    render json: Page.all
end

#updateObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/billy_cms/api/pages_controller.rb', line 8

def update
    render nothing: true, status: 400 unless params[:page]
    page = Page.find params[:id]
    if page.update_attributes page_params
        render json: {
            success: true,
            page: page
        }
    else
        render json: {
            success: false,
            error: page.errors.full_messages,
        }, status: 500
    end
end