Create a gist now

Instantly share code, notes, and snippets.

class BooksController < ApplicationController
def create
@book = Book.new(params[:book], as : current_user.try(:admin) ? :admin : :user)
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(params[:book], as :
current_user.try(:admin) ? :admin : :user)
format.html { redirect_to @book, notice : 'Book was successfully updated.' }
else
format.html { render action : "edit" }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment