Skip to content

Instantly share code, notes, and snippets.

@jgrannas
Last active December 20, 2015 20:59
Show Gist options
  • Select an option

  • Save jgrannas/6194740 to your computer and use it in GitHub Desktop.

Select an option

Save jgrannas/6194740 to your computer and use it in GitHub Desktop.

Revisions

  1. jgrannas revised this gist Aug 9, 2013. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,15 @@ def self.filter_with_params(params)
    end
    end
    scoped
    end
    end



    Started GET "/styles?utf8=%E2%9C%93&t%5B%5D=engagement&t%5B%5D=Halo" for 127.0.0.1 at 2013-08-09 11:58:46 -0400
    Processing by StylesController#index as JSON
    Parameters: {"utf8"=>"✓", "t"=>["engagement", "Halo"]}
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
     (0.4ms) SELECT 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)))
    Collection Load (0.3ms) SELECT "collections".* FROM "collections"
    SQL (0.4ms) SELECT "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, "styles"."meta_title" AS t0_r12, "styles"."meta_desc" AS t0_r13, "styles"."active" AS t0_r14, "tags"."id" AS t1_r0, "tags"."name" AS t1_r1, "tags"."created_at" AS t1_r2, "tags"."updated_at" AS t1_r3, "tags"."tag_category_id" AS t1_r4 FROM "styles" LEFT OUTER JOIN "tagizations" ON "tagizations"."style_id" = "styles"."id" LEFT OUTER JOIN "tags" ON "tags"."id" = "tagizations"."tag_id" WHERE "tags"."name" = 'engagement' AND "tags"."name" = 'Halo' AND (styles.name != '')
    Completed 200 OK in 22ms (Views: 0.1ms | ActiveRecord: 1.4ms)
  2. jgrannas renamed this gist Aug 9, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. jgrannas created this gist Aug 9, 2013.
    11 changes: 11 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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
    end