Skip to content

Instantly share code, notes, and snippets.

View khanhtripla's full-sized avatar

Khanh khanhtripla

View GitHub Profile
@lfender6445
lfender6445 / gist:9919357
Last active July 3, 2024 20:50
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@bf4
bf4 / polymorphic_many_to_many_in_rails.md
Last active February 6, 2024 21:13
a polymorphic many-to-many association in Rails

This was my solution for a polymorphic many-to-many association

class ItemCountry < ActiveRecord::Base
  belongs_to :locatable, :polymorphic => true
  belongs_to :country
  # fields are :locatable_id, :locatable_type, :country_id
end

class Title < ActiveRecord::Base

has_many :countries, :through => :item_countries, :as => :locatable