This file contains 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 MyModel < ActiveRecord::Base | |
# No corresponding table in the DB. | |
self.abstract_class = true | |
establish_connection(:ext_database) | |
def self.getCustomerId(first_name, last_name) | |
get = connection.select_one("SELECT * FROM customers WHERE First_Name=#{connection.quote(first_name)} AND Last_Name=#{connection.quote(last_name)}") | |
get.id | |
end |
This file contains 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 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 |
This file contains 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 Timeslip < ActiveRecord::Base | |
belongs_to :car | |
belongs_to :user | |
has_one :car_model, through: :car | |
has_one :transmission, through: :car | |
has_one :engine, through: :car | |
default_scope order('et1320 ASC') | |
This file contains 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
Started GET "/styles?utf8=%E2%9C%93&t%5B%5D=engagement" for 127.0.0.1 at 2013-08-09 13:38:51 -0400 | |
Processing by StylesController#index as JSON | |
Parameters: {"utf8"=>"✓", "t"=>["engagement"]} | |
[1m[35mUser Load (0.4ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 | |
[1m[36m (0.4ms)[0m [1mSELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = 1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))[0m | |
[1m[35mCollection Load (0.3ms)[0m SELECT "collections".* FROM "collections" | |
[1m[36mSQL (0.6ms)[0m [1mSELECT "styles"."id" AS t0_r0, "styles"."collection_id" AS t0_r1, "styles"."item_number" AS t0_r2, "styles"."name" AS t0_r3, "styles"."title" AS t0_r4, "styles"."description" AS t0_r5, "styles"."slug" AS t0_r6, "styles"."content" AS t0_r7, "styles"."created_at" AS t0_r8, "styles"."updated_at" AS t0_r9, "styles"."price" AS t0_r10, "styles"."data" AS t0_r11, "s |
This file contains 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
def self.filter_with_params(params) | |
scoped = self.where("styles.name != ''") | |
scoped = scoped.includes(:tags)#, :collection) | |
#params[:t].inject(scoped){|memo, val| memo.where(:tags => {:name => val})} if params[:t] | |
if params[:t] | |
params[:t].each do |t| | |
scoped = scoped.where(:tags => {:name => t}) | |
end | |
end | |
scoped |