Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from walidvb/Feature
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save universal/99b589ead411961c0e1f to your computer and use it in GitHub Desktop.

Select an option

Save universal/99b589ead411961c0e1f to your computer and use it in GitHub Desktop.
class BooksController < ApplicationController
before_action :load_book
before_action :check_access
def show
@comments = @book.comments.reversed_nested_set.with_state([:draft, :published])
end
def subscribed
end
private
def load_book
@book = Book.find_by_slug(params[:id]) or raise "No such book '#{params[:id]}'"
end
def check_access
if !@book.published? && !(current_user && current_user.admin?)
flash[:warning] = "Please login as admin to view this page"
redirect_to root_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment