public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.