Guest User

Untitled

a guest
Jan 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # This class is responsible for the Books REST interface.
  2. #
  3. class BooksController < ApplicationController
  4.  
  5. # Get a book by the id
  6. before_filter :get_book, only: [:edit, :update, :show, :destroy]
  7.  
  8. # Renders the form to create a new Book.
  9. #
  10. def new
  11. @book = Book.new
  12. end
  13.  
  14. # Creates a new Book from the params and redirects to edit view.
  15. #
  16. def create
  17. @book = Book.create(params[:book])
  18. redirect_to book_path(@book)
  19. end
  20.  
  21. # Renders the form for a given book.
  22. #
  23. def edit
  24. end
  25.  
  26. # Updates a Book from the params and redirects to edit view.
  27. #
  28. def update
  29. @book.update(params[:book])
  30. redirect_to edit_book_path(@book)
  31. end
  32.  
  33. # Renders all books
  34. #
  35. def index
  36. @books = Book.all
  37. end
  38.  
  39. # Renders a Book with its clips
  40. #
  41. def show
  42. end
  43.  
  44. # Destroys the Book object from database
  45. #
  46. def destroy
  47. @book.destroy
  48. redirect_to action: :index
  49. end
  50.  
  51. private
  52.  
  53. def get_book
  54. @book = Book.get(params[:id])
  55. end
  56. end
Add Comment
Please, Sign In to add comment