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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 2, 7:11 am, Thomas Eapen <thomas.ea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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". >The helper method is for including modules (or controller methods) into views. It''s not supposed to do anything to controllers. Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the info, Tom. On Jun 2, 5:38 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jun 2, 7:11 am, Thomas Eapen <thomas.ea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > The helper method is for including modules (or controller methods) > into views. It''s not supposed to do anything to controllers. > > Fred--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---