Skip to content

Commit

Permalink
Implement CRUD in kindles controller after CORS implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Heriberto Perez committed Feb 3, 2014
1 parent c72fa96 commit f3a66c6
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions app/controllers/api/kindles_controller.rb
Expand Up @@ -2,11 +2,39 @@ class Api::KindlesController < ApplicationController
respond_to :json
PER_PAGE_RECORDS = 9

skip_before_filter :verify_authenticity_token

def index
kindles_paginated = Kindle.order('id').page(params[:page]).per(PER_PAGE_RECORDS)
json_response = {
models: kindles_paginated,
current_page: params[:page].to_i,
perPage: PER_PAGE_RECORDS,
total_pages: kindles_paginated.num_pages
}
respond_with json_response
end

def create
kindle = Kindle.create(kindle_params)
respond_with kindle, location: nil
end

def show
respond_with Kindle.find(params[:id])
end

def update
respond_with Kindle.update(params[:id], kindle_params)
end

def destroy
respond_with Kindle.destroy(params[:id])
end

private

respond_to do |format|
format.json { render :json => { models: kindles_paginated, current_page: params[:page].to_i, perPage: PER_PAGE_RECORDS, total_pages: kindles_paginated.num_pages }, callback: params[:callback] }
end
def kindle_params
params.require(:kindle).permit(:inventory_id, :status)
end
end

0 comments on commit f3a66c6

Please sign in to comment.