Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Aditya Kapoor aditya-kapoor

🎯
Focusing
View GitHub Profile
@aditya-kapoor
aditya-kapoor / audited gem problems
Last active Dec 16, 2015
This gist is written to highlight an issue which is coming up with the audited gem by collectiveidea
View audited gem problems
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 Apr 17, 2013
Rails Validations not running when I use :on => :save option
View Rails validations not running
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 Dec 17, 2015
This is the benchmark file that would demonstrate the speed differences between class_eval and define_method
View Benchmark
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
)