Skip to content

Instantly share code, notes, and snippets.

View aditya-kapoor's full-sized avatar
🎯
Focusing

Aditya Kapoor aditya-kapoor

🎯
Focusing
View GitHub Profile
@aditya-kapoor
aditya-kapoor / audited gem problems.md
Last active September 11, 2023 09:36
This gist is written to highlight an issue which is coming up with the audited gem by collectiveidea

The audited gem is a powerful gem that helps us keeping the log of the changes that are made to the models. This gem does its job excellently but there are some issues which I have discovered when I was reading this gem..

Suppose I have a model named Customer as shown below

class Customer < ActiveRecord::Base
  attr_accessible :first_name
  audited comment_required: true
end
@aditya-kapoor
aditya-kapoor / Rails validations not running
Created April 17, 2013 13:26
Rails Validations not running when I use :on => :save option
This gist is in reference to the documentation for the Rails 3.2.13 on Ruby 1.9.3 p194 (http://guides.rubyonrails.org/active_record_validations_callbacks.html#on) where it has highlighted the fact that the validations for presence can also be run using the :on => :save option. The following code will highlight it better
class User < ActiveRecord::Base
attr_accessible :name
validates :name, :presence => true, :on => :save
end
u = User.create
u.errors #=> nil
@aditya-kapoor
aditya-kapoor / Benchmark
Last active December 17, 2015 07:39
This is the benchmark file that would demonstrate the speed differences between class_eval and define_method
require 'benchmark'
require 'benchmark/ips'
GC.disable
UNSAFE_STRING_METHODS = %w(
capitalize chomp chop delete downcase gsub lstrip next reverse rstrip
slice squeeze strip sub succ swapcase tr tr_s upcase prepend
)