Skip to content

Instantly share code, notes, and snippets.

@raysrashmi
Created November 11, 2012 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raysrashmi/4055673 to your computer and use it in GitHub Desktop.
Save raysrashmi/4055673 to your computer and use it in GitHub Desktop.
class BooksController < ApplicationController
def create
@book = Book.new(params[:book], as : user_role)
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 :
user_role)
format.html { redirect_to @book, notice : 'Book was successfully updated.' }
else
format.html { render action : "edit" }
end
end
end
private
def user_role
current_user.try(:admin) ? :admin : (current_user.try(:user) ? :user : :reporting_user)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment