Skip to content

Instantly share code, notes, and snippets.

@vokshirg
vokshirg / migration_example.rb
Created December 11, 2023 17:51
Migration example with stubbed models
class MergePaypalVerificationAndContacts < ActiveRecord::Migration[7.0]
class User < ApplicationRecord
self.table_name = :users
has_many :user_verifications, class_name: 'UserVerification'
has_one :paypal_verification, class_name: 'OldPaypalVerification'
end
class UserVerification < ApplicationRecord
self.table_name = :user_verifications
self.inheritance_column = :_type_disabled
@vokshirg
vokshirg / Makefile
Created May 12, 2022 13:27 — forked from hulous/Makefile
Rails app Docker and docker-compose command abstraction
APPLICATION_NAME = scubadiveslog # main app name or workdir defined in Dockerfile
WEB_CONTAINER_NAME = scuba-web # web container as defined in docker-compose
.DEFAULT_GOAL := help
# Docker stuff
attach: ## Attach running web container to see logs
docker attach $(APPLICATION_NAME)_$(WEB_CONTAINER_NAME)_1
up: ## Run containers
docker-compose up -d
asdasd
@vokshirg
vokshirg / answer.rb
Created May 15, 2016 15:56
Fail with answer's specs
class Answer < ActiveRecord::Base
belongs_to :question
belongs_to :user
validates :body, :question_id, :user_id, presence: true
default_scope { order("right_answer DESC").order("created_at DESC") }
def is_right_answer
self.question.answers.where("right_answer = ?", true).update_all("right_answer = false")