helper :all does not include Modules

Thomas Eapen
Mon, 02 Jun 2008 06:11:45 -0000

Greetings list,

I was wondering if any of you are unable to call "helper" methods in
your controllers even though application.rb has a call to
"helper :all"?

My views are able to call the methods but my controllers are unable to
call them unless I "include ModuleHelper" in the controller but I was
under the impression that helper :all is supposed to take care of the
"including".

My development environment is
Rails 2.1.0

application.rb snippet::

--------------------------------------------------------------------------------------------------------
class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time (but doesn''t seem
to)

  #controllers can call helper methods from this helper below only if
the line below is uncommented.
  #include AuthenticateHelper

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you''re not using the cookie session store
  protect_from_forgery :secret =>
''xxxxxxxxxxxxxxxxxxxxxxxxxxxxx''

end
---------------------------------------------------------------------------------------------------------

user_controller.rb snippet::

---------------------------------------------------------------------------------------------------------

class UserController < ApplicationController
  before_filter :protect, :only => :index

  def index
  end

  # Call to logged_in? (in the method below) which is a helper module
method does not work unless
  # the module is explicitely included in the ApplicationController or
this specific controller

  def protect
    unless logged_in?
      session[:protected_page] = request.request_uri
      flash[:notice] = "Please log in first"
      redirect_to :action => "login"
      return false
    end
  end

  private :protect
end
-----------------------------------------------------------------------------------------------------------

authenticate_helper.rb snippet::

-----------------------------------------------------------------------------------------------------------

module AuthenticateHelper

  # Checks if a user is logged in
  def logged_in?
    not session[:user_id].nil?
  end

end

----------------------------------------------------------------------------------------------------------

Calling the helper method on a single module helper doesn''t seem to
bring the methods into the controller either.

-----------------------------------
helper :authenticate
# or
helper AuthenticateHelper
-----------------------------------


Standard, simple code. Any help is much appreciated.

Tom.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org