Skip to content

Instantly share code, notes, and snippets.

View kyprifog's full-sized avatar

Kyle Prifogle kyprifog

View GitHub Profile
@kyprifog
kyprifog / create_user.rb
Created March 4, 2016 19:26
Strong Parameters in Service Object
class CreateUser
def initialize(params)
@params = user_params(params)
@user = User.new(@params)
end
def perform
ActiveRecord::Base.transaction do
# do stuff
@kyprifog
kyprifog / pluck_all.rb
Created October 6, 2015 20:41
Active Record Pluck All
# pluck_all.rb
module ActiveRecord
class Relation
def pluck_all(*args)
args.map! do |column_name|
if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
"#{connection.quote_table_name(table_name)}.#{connection.quote_column_name(column_name)}"
else
column_name.to_s
end