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
| squirrel_staging=> explain analyze select distinct on (bet_id) bet_id, sport_id from sports_bet_selections sbs ; | |
| QUERY PLAN | |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Unique (cost=0.00..3000.21 rows=62774 width=8) (actual time=0.121..245.682 rows=65640 loops=1) | |
| -> Index Scan using index_sports_bet_selections_on_bet_id on sports_bet_selections sbs (cost=0.00..2827.03 rows=69274 width=8) (actual time=0.117..99.272 rows=69624 loops=1) | |
| Total runtime: 308.829 ms | |
| (3 rows) | |
| squirrel_staging=> explain analyze select bet_id from sports_bet_selections sbs where sbs.id = (select max(id) from sports_bet_selections where bet_id = sbs.bet_id); | |
| QUERY PLAN |
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
| #app/decorators/application.rb | |
| class ApplicationDecorator < Draper::Decorator | |
| def link_to_edit | |
| if h.can? :edit, object | |
| h.link_to 'Edytuj', h.public_send("edit_#{object.class.name.underscore}_path", object) | |
| end | |
| end | |
| def link_to_destroy |
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 GplusApi | |
| cattr_reader :plus, :key, :token_expiration | |
| attr_reader :client | |
| private :key | |
| def initialize(user_id) | |
| client_set_up | |
| @user_id = user_id | |
| end |
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
| > search = AdvertSearch.new(brand: 'Honda', production_year_gte: 2000, production_year_lte: 2004, last_week: true) | |
| > search.results.to_sql | |
| => "SELECT \"adverts\".*" | |
| "FROM \"adverts\"" | |
| "WHERE \"adverts\".\"brand\" = 'Honda'" | |
| "AND (`adverts`.`production_year` >= 2000)" | |
| "AND (`adverts`.`production_year` <= 2004)" | |
| "AND (\"adverts\".\"published_at\" BETWEEN '2014-10-28 00:00:00.000000' AND '2014-11-04 00:00:00.000000')" | |
| > squery = SavedQuery.create!(name: 'honda for my friend', advert_search: search) |
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
| #app/models/saved_query.rb | |
| class SavedQuery < ActiveRecord::Base | |
| embeds_one :advert_search, column_name: :query_params | |
| end |
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
| #app/searches/advert_search.rb | |
| class AdvertSearch < Searchlight::Search | |
| extend Embedson::Model | |
| embedded_in :saved_query | |
| search_on Advert.all | |
| searches :brand, :production_year_gte, :production_year_lte, :last_week |
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
| > rails generate model saved_query name:text query_params:json | |
| > rake db:migrate |
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
| Advert.where( brand: ‘Honda’, | |
| production_year: 2000..2004, | |
| published_at: (Time.current - 1.week).at_beginning_of_day..Time.current.at_beginning_of_day | |
| ) |
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
| # og_hash looks like this | |
| # og_title and og_type are calculated | |
| # also image_url | |
| def og_hash | |
| og_h = { | |
| title: og_title, | |
| type: og_type, | |
| description: text | |
| } | |
| og_h.merge(image: image_url) if image_url.present? |
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
| 2.1.1 :052 > t = Test.new() | |
| => #<Test id: nil, data: nil, created_at: nil, updated_at: nil> | |
| 2.1.1 :053 > t.virt = Virt.new(address: { street: 'pięknie jest', nr: 5 }) | |
| => #<Virt:0x00000106100458 @address={:street=>"pięknie jest", :nr=>5}, @name=nil, @children=[]> | |
| 2.1.1 :054 > t.save! | |
| (0.4ms) BEGIN | |
| SQL (0.4ms) INSERT INTO "tests" ("created_at", "data", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["created_at", "2014-10-07 21:56:49.991978"], ["data", "{\"name\":null,\"address\":{\"street\":\"pięknie jest\",\"nr\":5},\"children\":[]}"], ["updated_at", "2014-10-07 21:56:49.991978"]] | |
| (2.0ms) COMMIT | |
| => true | |
| 2.1.1 :055 > t.reload |
NewerOlder