Skip to content

Instantly share code, notes, and snippets.

@jgrannas
Last active December 27, 2015 00:18
Show Gist options
  • Save jgrannas/7236401 to your computer and use it in GitHub Desktop.
Save jgrannas/7236401 to your computer and use it in GitHub Desktop.
Homes model, featured charts
class HomesController < ApplicationController
#load_and_authorize_resource
def index
@featured_charts = Chart.featured
#I want to have one object, and run through and run the below methods on each Chart.featured instead of seperate lines below
#If i try and run Chart.featured.items.each_car_fastest.ordered_by_et.topten i get error
@list1 = Chart.find(1).items.each_car_fastest.ordered_by_et.topten#dynamic_query("car_model","name","Supra (MKIV)").dynamic_query("transmission","name","Getrag 6-Speed (V160)").each_car_fastest.topten
@list2 = Chart.find(2).items.each_car_fastest.ordered_by_et.topten#dynamic_query("car_model","name","Supra (MKIV)").dynamic_query("transmission","name","Getrag 6-Speed (V160)").each_car_fastest.topten
@list3 = Chart.find(3).items.each_car_fastest.ordered_by_et.topten#dynamic_query("car_model","name","Supra (MKIV)").dynamic_query("transmission","name","Getrag 6-Speed (V160)").each_car_fastest.topten
@recent_timeslips = Timeslip.recents
@recent_dynos = Dyno.recents
end
end
#CHART MODEL
class Chart < ActiveRecord::Base
has_many :chart_conditions, :dependent => :destroy
accepts_nested_attributes_for :chart_conditions, allow_destroy: true
validates :name, :category, presence: true
def items
mymodel = category.capitalize.constantize
#CHART CONDITIONS
mymodel.dynamic_query(chart_conditions).each_car_fastest.ordered_by_et#.to_a
#mymodel.dynamic_query(cc.assoc_name,cc.name,cc.value)#.all#includes(:car).where(:car => {:car_model_id => CarModel.find_by_name("Supra (MKIV)").id})
end
def self.featured
where(:featured => true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment