Skip to content

Instantly share code, notes, and snippets.

@kbaum
Last active December 30, 2015 23:39
Show Gist options
  • Save kbaum/7902401 to your computer and use it in GitHub Desktop.
Save kbaum/7902401 to your computer and use it in GitHub Desktop.
my portfolio optimized
class MyPortfoliosController < ApplicationController
before_filter :authenticate_user!
helper_method :portfolio_spaces
helper_method :portfolio_properties
def show
end
private
def portfolio_properties
my_portfolio_filter.filtered_properties
end
def portfolio_spaces
my_portfolio_filter.filtered_spaces
end
class MyPortfolioFilter
def filtered_spaces
@filtered_spaces ||= filtered_spaces_query(filtered_properties.collect(&:id)).includes(:videos, :property => :users)
end
def filtered_properties
@filtered_properties ||= user.my_properties.where(id: filtered_spaces_query.pluck(:property_id).uniq)
.includes(:city, :submarket, :photos, :videos, :spaces)
.page(page)
.per(10)
.decorate
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment