public
Description: Conditional checks on Rails filters
Clone URL: git://github.com/thoughtbot/when.git
updated README w/ what we dont support

git-svn-id: https://svn.thoughtbot.com/plugins/when/trunk@338 
7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
jcarroll (author)
Thu Feb 14 14:50:59 -0800 2008
commit  751f3da9647fc094c93c6e38f9ad46879aeb2b76
tree    c4d26bdef95fa102600a10dff0e469fcddb5afd9
parent  d7040373acafc9c579ca61f242536eff4d395878
0
...
91
92
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
...
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
0
@@ -91,4 +91,34 @@ before_filter :log_in!,
0
   :only => [:new, :create],
0
   :unless => :logged_in?
0
 
0
+What When does NOT support
0
+==========================
0
+
0
+# ActiveRecord String callbacks
0
+before_create 'self.password = password.to_sha1',
0
+ :unless => lambda {|user| user.password_confirmation.blank?}
0
+
0
+# ActiveRecord Class callbacks
0
+before_create PasswordEncryptor,
0
+ :unless => lambda {|user| user.password_confirmation.blank?}
0
+
0
+# ActiveRecord Block callbacks
0
+before_create(:unless => lambda {|user| user.password_confirmation.blank?}) do |record|
0
+ record.password = record.password.to_sha1
0
+end
0
+
0
+# ActionController Block filters
0
+before_filter(:unless => :logged_in?) do |controller|
0
+ redirect_to new_session_path
0
+end
0
+
0
+# ActionController Class filters
0
+before_filter Authorizer,
0
+ :unless => :logged_in?
0
+
0
+When will not work if your code contains any of these.
0
+
0
+In our experience we've never used any of these types of callbacks and filters. By using Symbols, i.e. methods,
0
+the resulting code is much more intention revealing. Class callbacks and filters we feel are most of the time overkill.
0
+
0
 Copyright (c) 2008 Jared Carroll and Dan Croak, released under the MIT license

Comments

    No one has commented yet.