Class: Api::PagesController
- Inherits:
-
ApiController
- Object
- ActionController::Base
- ApiController
- Api::PagesController
- Defined in:
- app/controllers/api/pages_controller.rb
Instance Method Summary collapse
Methods inherited from ApiController
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/api/pages_controller.rb', line 27 def create return render nothing: true, status: 400 unless params[:page] page = BillyCms::Page.new page_params if page.save render json: { success: true, page: page } else render json: { success: false, error: page., }, status: 500 end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/api/pages_controller.rb', line 43 def destroy return render :nothing, status: 400 unless params[:id] return render :nothing, status: 404 unless page = BillyCms::Page.where(id: params[:id]).first if page.destroy render json: { success: true } else render json: { success: false, error: page., }, status: 500 end end |
#index ⇒ Object
3 4 5 |
# File 'app/controllers/api/pages_controller.rb', line 3 def index render json: BillyCms::Page.all end |
#show ⇒ Object
7 8 9 |
# File 'app/controllers/api/pages_controller.rb', line 7 def show render json: BillyCms::Page.find(params[:id]) end |
#update ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/api/pages_controller.rb', line 11 def update return render nothing: true, status: 400 unless params[:page] page = BillyCms::Page.find params[:id] if page.update_attributes page_params render json: { success: true, page: page } else render json: { success: false, error: page.errors., }, status: 500 end end |