aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/abstract/helpers.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-05-23 00:17:05 +0200
committerPratik Naik <pratiknaik@gmail.com>2009-05-23 00:17:10 +0200
commite976c489e6416cdc4714721df78dd43dd6d13d99 (patch)
treec5e5c96ef0bd5cd522ddc492a527e53685a0d58b /actionpack/lib/action_controller/abstract/helpers.rb
parent1d168afcb146872cb7e49b6d513629fbb19e39b0 (diff)
downloadrails-e976c489e6416cdc4714721df78dd43dd6d13d99.tar.gz
rails-e976c489e6416cdc4714721df78dd43dd6d13d99.tar.bz2
rails-e976c489e6416cdc4714721df78dd43dd6d13d99.zip
Add all the existing helpers related features to the new base
Diffstat (limited to 'actionpack/lib/action_controller/abstract/helpers.rb')
-rw-r--r--actionpack/lib/action_controller/abstract/helpers.rb27
1 files changed, 23 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/abstract/helpers.rb b/actionpack/lib/action_controller/abstract/helpers.rb
index 968d3080c1..41decfd0c7 100644
--- a/actionpack/lib/action_controller/abstract/helpers.rb
+++ b/actionpack/lib/action_controller/abstract/helpers.rb
@@ -24,11 +24,30 @@ module AbstractController
super
end
-
+
+ # Makes all the (instance) methods in the helper module available to templates rendered through this controller.
+ # See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules
+ # available to the templates.
def add_template_helper(mod)
master_helper_module.module_eval { include mod }
end
-
+
+ # Declare a controller method as a helper. For example, the following
+ # makes the +current_user+ controller method available to the view:
+ # class ApplicationController < ActionController::Base
+ # helper_method :current_user, :logged_in?
+ #
+ # def current_user
+ # @current_user ||= User.find_by_id(session[:user])
+ # end
+ #
+ # def logged_in?
+ # current_user != nil
+ # end
+ # end
+ #
+ # In a view:
+ # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
def helper_method(*meths)
meths.flatten.each do |meth|
master_helper_module.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
@@ -39,14 +58,14 @@ module AbstractController
end
end
- def helper(*args, &blk)
+ def helper(*args, &block)
args.flatten.each do |arg|
case arg
when Module
add_template_helper(arg)
end
end
- master_helper_module.module_eval(&blk) if block_given?
+ master_helper_module.module_eval(&block) if block_given?
end
end