Sha256: 39c26534ee6faac3b9f5bc6cd01c8549db9e2c1f6004b978d4a0a4a73b8f189b
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
# It will works with respond_with. # Your action should looks like any other one: A model with a method call. =D class BookController < ApplicationController # It will hit http://api.example.com/books with a get request def index @books = Book.all respond_with(@books) end # It will initialize a new object based on the attribute accessors def new @book = Book.new respond_with(@book) end # It will hit http://api.example.com/books with a post request def create @book = Book.create(params[:book]) respond_with(@user) end # It will hit http://api.example.com/books/1 with a get request def edit @book = Book.find(params[:id]) respond_with(@book) end # It will hit http://api.example.com/books with a put request def update @book = Book.update_attributes(params[:id], params[:book]) respond_with(@book) end # It will hit http://api.example.com/books/1 with a get request def show @book = Book.find(params[:id]) respond_with(@book) end # It will hit http://api.example.com/books/1 with a delete request def delete @book = Book.destroy(params[:id]) respond_with(@book) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
api-client-3.1.0 | examples/controllers/book_controller.rb |
api-client-3.0.0 | examples/controllers/book_controller.rb |