aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorLuke Gruber <luke.gru@gmail.com>2012-03-15 16:40:23 -0400
committerLuke Gruber <luke.gru@gmail.com>2012-03-15 16:40:23 -0400
commitaca693776047f6582109290c4834a3caccfadcc3 (patch)
tree3a67b13d7c27eb88a1ac6df8a9f07f92c8b41ca7 /actionpack/lib
parente6c95fe3915bdc1eb1fffd5e508003f0d5f5ad78 (diff)
downloadrails-aca693776047f6582109290c4834a3caccfadcc3.tar.gz
rails-aca693776047f6582109290c4834a3caccfadcc3.tar.bz2
rails-aca693776047f6582109290c4834a3caccfadcc3.zip
allow zero-arity proc for AbstrController::layout
proc without parameters can now be given to AbstractController::layout
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/layouts.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/abstract_controller/layouts.rb b/actionpack/lib/abstract_controller/layouts.rb
index 683a2628a4..3897287af5 100644
--- a/actionpack/lib/abstract_controller/layouts.rb
+++ b/actionpack/lib/abstract_controller/layouts.rb
@@ -89,7 +89,7 @@ module AbstractController
# class TillController < BankController
# layout false
#
- # In these examples, we have three implicit lookup scenrios:
+ # In these examples, we have three implicit lookup scenarios:
# * The BankController uses the "bank" layout.
# * The ExchangeController uses the "exchange" layout.
# * The CurrencyController inherits the layout from BankController.
@@ -128,7 +128,14 @@ module AbstractController
# If you want to use an inline method, such as a proc, do something like this:
#
# class WeblogController < ActionController::Base
- # layout proc{ |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
+ # layout proc { |controller| controller.logged_in? ? "writer_layout" : "reader_layout" }
+ # end
+ #
+ # If an argument isn't given to the proc, it's evaluated in the context of
+ # the current controller anyway.
+ #
+ # class WeblogController < ActionController::Base
+ # layout proc { logged_in? ? "writer_layout" : "reader_layout" }
# end
#
# Of course, the most common way of specifying a layout is still just as a plain template name:
@@ -299,8 +306,8 @@ module AbstractController
end
RUBY
when Proc
- define_method :_layout_from_proc, &_layout
- "_layout_from_proc(self)"
+ define_method :_layout_from_proc, &_layout
+ _layout.arity == 0 ? "_layout_from_proc" : "_layout_from_proc(self)"
when false
nil
when true