Skip to content

Instantly share code, notes, and snippets.

@drewtempelmeyer
Created July 28, 2017 21:41
Show Gist options
  • Save drewtempelmeyer/fee0a2d97767296ad6c9b60ab9f67178 to your computer and use it in GitHub Desktop.
Save drewtempelmeyer/fee0a2d97767296ad6c9b60ab9f67178 to your computer and use it in GitHub Desktop.
class Funko
# Add these scopes to your model
scope :for_user, ->(user) { where(user: user) }
scope :for_category, ->(category) { joins(:category).where(categories: { name: category }) }
scope :newest, -> { order(created_at: :desc) }
end
def index
category = params[:category]
@funkos = Funko.newest
@funkos = @funkos.for_user(current_user) if user_signed_in?
@funkos = @funkos.for_category(category) if category.present?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment