Created
November 11, 2012 18:05
-
-
Save raysrashmi/4055729 to your computer and use it in GitHub Desktop.
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
class BooksController < ApplicationController | |
def create | |
@book = Book.new(book_params) | |
respond_to do |format| | |
if @book.save | |
format.html { redirect_to @book, notice : 'Book was successfully created.' } | |
else | |
format.html { render action : "new" } | |
end | |
end | |
end | |
def update | |
@book = Book.find(params[:id]) | |
respond_to do |format| | |
if @book.update_attributes(book_params) | |
format.html { redirect_to @book, notice : 'Book was successfully updated.' } | |
else | |
format.html { render action : "edit" } | |
end | |
end | |
end | |
private | |
def book_params | |
if current_user && current_user.admin? | |
params[:book].permit(:name, :author, :public) | |
else | |
params[:book].permit(:name, :author) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment