Sha256: 145c8a6ea98c20474ae333a6990089899ab840e329dd120834a9b6da60c361b2

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 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(:book => 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], { :book => 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

1 entries across 1 versions & 1 rubygems

Version Path
api-client-2.7.0 examples/controllers/book_controller.rb