Skip to content

Instantly share code, notes, and snippets.

marcelorxaviers

Block or report user

Report or block marcelorxaviers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View batch_create_do_nothing.rb
class BatchCreate
class << self
def perform(active_records:, conflict_fields:)
return if active_records.empty?
ActiveRecord::Base.connection.execute(
<<-SQL.squish
#{insert_statement(active_records.first)}
#{values(active_records)}
#{on_conflict_statement(conflict_fields)}
View batch_create.rb
class BatchCreate
class << self
def perform(active_records:, conflict_fields:)
return if active_records.empty?
ActiveRecord::Base.connection.execute(
<<-SQL.squish
#{insert_statement(active_records.first)}
#{values(active_records)}
#{on_conflict_statement(active_records.first, conflict_fields)}
View routes.rb
if Rails.env.development?
class MarcelosController < ApplicationController
def method
require 'pry-byebug' ; binding.pry
end
end
get '/marcelos_method/:id', to: 'marcelos#method'
end
@marcelorxaviers
marcelorxaviers / flatten.rb
Last active Jun 26, 2017
Flatten method for array in Ruby
View flatten.rb
# flatten.rb
module Flatten
extend self
def perform!(array, type = nil)
return [] if type == Array
recursive(array.to_a, type)
rescue
raise "The parameter has to be a #{type || "mixed types"} collection."
You can’t perform that action at this time.