Created
July 28, 2017 21:41
-
-
Save drewtempelmeyer/fee0a2d97767296ad6c9b60ab9f67178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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