-
-
Save radar/2dd551d2f6f98d8e252f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class BooksController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
@books = current_user.books | |
end | |
def new | |
@book = Book.new | |
end | |
def create | |
@book = current_user.books.build(book_params) | |
if @book.save | |
redirect_to root_path, notice: "Book created" | |
else | |
render :new | |
end | |
end | |
private | |
def book_params | |
params.require(:book).permit(:title) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment