Created
October 6, 2011 18:17
-
-
Save mrcasals/1268166 to your computer and use it in GitHub Desktop.
Rails Controllers with DataMapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class is responsible for the Books REST interface. | |
# | |
class BooksController < ApplicationController | |
# Get a book by the id | |
before_filter :get_book, only: [:edit, :update, :show, :destroy] | |
# Renders the form to create a new Book. | |
# | |
def new | |
@book = Book.new | |
end | |
# Creates a new Book from the params and redirects to edit view. | |
# | |
def create | |
@book = Book.create(params[:book]) | |
redirect_to book_path(@book) | |
end | |
# Renders the form for a given book. | |
# | |
def edit | |
end | |
# Updates a Book from the params and redirects to edit view. | |
# | |
def update | |
@book.update(params[:book]) | |
redirect_to edit_book_path(@book) | |
end | |
# Renders all books | |
# | |
def index | |
@books = Book.all | |
end | |
# Renders a Book | |
# | |
def show | |
end | |
# Destroys the Book object from database | |
# | |
def destroy | |
@book.destroy | |
redirect_to action: :index | |
end | |
private | |
def get_book | |
@book = Book.get(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment