CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sun, 24 Aug 2025 13:57:09 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100215094959
location: https://web.archive.org/web/20100215094959/https://github.com/thoughtbot/when
server-timing: captures_list;dur=0.478501, exclusion.robots;dur=0.016345, exclusion.robots.policy;dur=0.007330, esindex;dur=0.010578, cdx.remote;dur=66.003334, LoadShardBlock;dur=384.802530, PetaboxLoader3.datanode;dur=47.163425, PetaboxLoader3.resolve;dur=138.328381
x-app-server: wwwb-app203
x-ts: 302
x-tr: 477
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app203; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sun, 24 Aug 2025 13:57:11 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.7.61
x-archive-orig-date: Mon, 15 Feb 2010 09:49:59 GMT
x-archive-orig-connection: close
x-archive-orig-status: 200 OK
x-archive-orig-etag: "2d12b36e361443fa4eec83f76c01cbf0"
x-archive-orig-x-runtime: 161ms
x-archive-orig-content-length: 25728
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Mon, 15 Feb 2010 09:49:59 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 03 May 2008 07:52:44 GMT", ; rel="prev memento"; datetime="Sat, 16 Jan 2010 18:52:11 GMT", ; rel="memento"; datetime="Mon, 15 Feb 2010 09:49:59 GMT", ; rel="next memento"; datetime="Fri, 19 Feb 2010 03:29:07 GMT", ; rel="last memento"; datetime="Sun, 20 Sep 2020 04:17:45 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: TLA-20100215075433-00818-00827-ia360904-20100215221925-00000-c/TLA-20100215085230-00829-ia360906.us.archive.org.warc.gz
server-timing: captures_list;dur=0.543401, exclusion.robots;dur=0.020225, exclusion.robots.policy;dur=0.009755, esindex;dur=0.009870, cdx.remote;dur=7.735396, LoadShardBlock;dur=375.381598, PetaboxLoader3.datanode;dur=208.474759, PetaboxLoader3.resolve;dur=445.199892, load_resource;dur=504.710443
x-app-server: wwwb-app203
x-ts: 200
x-tr: 944
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
thoughtbot's when at master - GitHub
This service is courtesy of Pledgie.
thoughtbot / when
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
click here to add a description
click here to add a homepage
-
Branches (1)
- master ✓
- Tags (0)
Sending Request…
Enable Donations
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
Conditional checks on Rails filters. The same functionality was added to Rails 2.1, so this is only necessary for pre-Rails 2.1 apps. — Read more

dcroak (author)
Mon Feb 18 22:14:25 -0800 2008
when /
name | age | message | |
---|---|---|---|
![]() |
MIT-LICENSE | Wed Feb 13 16:25:45 -0800 2008 | updated the README git-svn-id: https://svn.tho... [jcarroll] |
![]() |
README | Fri Feb 15 08:07:43 -0800 2008 | README message about Obsoleteness git-svn-id: ... [dcroak] |
![]() |
Rakefile | Mon Feb 11 18:43:52 -0800 2008 | test and README files git-svn-id: https://svn.... [dcroak] |
![]() |
init.rb | Mon Feb 11 22:32:55 -0800 2008 | refactoring tests git-svn-id: https://svn.thou... [dcroak] |
![]() |
install.rb | Mon Feb 11 18:23:48 -0800 2008 | added when plugin skeleton git-svn-id: https:/... [dcroak] |
![]() |
lib/ | Thu Feb 14 21:36:09 -0800 2008 | fixed callbacks String condition git-svn-id: h... [jcarroll] |
![]() |
test/ | Mon Feb 18 22:14:25 -0800 2008 | made the string change to constants git-svn-id... [dcroak] |
![]() |
uninstall.rb | Mon Feb 11 18:23:48 -0800 2008 | added when plugin skeleton git-svn-id: https:/... [dcroak] |
README
When ==== When adds :if and :unless conditions to ActiveRecord callbacks and validations and ActionController filters. It works exactly the way as the current implementation of #validates_acceptance_of. It works on the 12 regular callbacks: before_validation before_validation_on_create after_validation after_validation_on_create before_save before_create before_update after_create after_update after_save before_destroy after_destroy 3 validations: validate validate_on_create validate_on_update and 1 filter: before_filter It works when :if or :unless is passed a Symbol, a Proc or a String. They return or evaluate to a true or false value. Example ======= class Address < ActiveRecord::Base before_save :geolocate def geolocate if complete? ... end end def complete? street? && city? && state? && zip? end end In this case, we want to find the latitude and longitude of an address only if the address is complete. Wrapping the entirety of a callback method with conditional logic is bad form. The callback should execute WHEN the model's life cycle reaches its "before_save" point and WHEN its address is "complete." With When, the WHEN responsibility is moved to where it belongs: as part of the callback. class Address < ActiveRecord::Base before_save :geolocate, :if => :complete? def geolocate ... end def complete? street? && city? && state? && zip? end end before_create's single responsibility is to execute code WHEN certain conditions are met. geolocate's single responsibility is to ... geolocate. It should not contain its own preconditions. More Examples ============= before_create :encrypt_password, :unless => lambda {|user| user.password_confirmation.blank?} before_filter :log_in!, :only => [:new, :create], :unless => :logged_in? What When does NOT support ========================== # ActiveRecord Class callbacks before_create PasswordEncryptor, :unless => lambda {|user| user.password_confirmation.blank?} # ActionController Class filters before_filter Authorizer, :unless => :logged_in? When will not work if your code contains any of these. In our experience we've never used class callbacks or filters and find them to be overkill. Obsolete after Rails 2.0.3 ========================== Whenever the next release after Rails 2.0.2 comes out, this feature will be baked into Rails via the ActiveSupport::Callbacks module. Happy coding! Installation ============ piston import https://svn.thoughtbot.com/plugins/when/trunk vendor/plugins/when Copyright (c) 2008 Jared Carroll, Dan Croak, and thoughtbot, inc. released under the MIT license