GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of lifo/doc-rails
Description: Repository for improving Rails documentation
Homepage: http://www.rubyonrails.org
Clone URL: git://github.com/zmalltalker/doc-rails.git
Extended the example code for helper_method, and made it a bit more 
sensible
leethal (author)
Fri Apr 11 06:42:17 -0700 2008
commit  1b73d91b5705f188e7bd36078c5a26348759e790
tree    056c47d4020b097c2e95fb8b1f975d98037c2043
parent  24fa99616202f06caf41642aca07943dcdd8b632
...
143
144
145
146
 
 
147
148
 
149
 
 
 
 
150
 
 
 
151
152
153
...
143
144
145
 
146
147
148
 
149
150
151
152
153
154
155
156
157
158
159
160
161
0
@@ -143,11 +143,19 @@ module ActionController #:nodoc:
0
       # Declare a controller method as a helper. For example, the following
0
       # makes the +current_user+ controller method available to the view:
0
       # class ApplicationController < ActionController::Base
0
- # helper_method :current_user
0
+ # helper_method :current_user, :logged_in?
0
+ #
0
       # def current_user
0
- # @current_user ||= User.find(session[:user])
0
+ # @current_user ||= User.find_by_id(session[:user])
0
       # end
0
+ #
0
+ # def logged_in?
0
+ # current_user != nil
0
+ # end
0
       # end
0
+ #
0
+ # In a view:
0
+ # <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
0
       def helper_method(*methods)
0
         methods.flatten.each do |method|
0
           master_helper_module.module_eval <<-end_eval

Comments

    No one has commented yet.