Sha256: a02ab318c1280deec30dccc6fb6eecee368a4440bef7a4491f791945c0b7bb43
Contents?: true
Size: 1.16 KB
Versions: 4
Compression:
Stored size: 1.16 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({ :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
4 entries across 4 versions & 1 rubygems