truetype
2007-Dec-30 13:59 UTC
Why are some methods of library accessible, while others are not? (by the example of restful_authentication)
If you have a model ''user'' generated through restful_authentication generator, then you should have an accessor def current_user @current_user ||= ... end inside the file authenticated_system.rb in lib folder. If you did as it is recommended and put ''include AuthenticatedSystem'' in ApplicationController, then now you have an access to the method ''current_user'' in any view. The same for method ''logged_in?''. Now try doing the same for method ''login_required'', which is also inside of AuthenticatedSystem module. Doesn''t work. Reads "undefined local variable or method ''login_required''". Summing up, both ''logged_in?'' and ''login_required'' are inside of Authenticated System module. ''logged_in?'' is accessible from any view, while ''login_required'' is not. What''s the difference? Thanx --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jean-François Trân
2007-Dec-30 14:14 UTC
Re: Why are some methods of library accessible, while others are not? (by the example of restful_authentication)
Oleg :> If you have a model ''user'' generated through restful_authentication > generator, then you should have an accessor > > def current_user > @current_user ||= ... > end > > inside the file authenticated_system.rb in lib folder. If you did as > it is recommended and put ''include AuthenticatedSystem'' in > ApplicationController, then now you have an access to the method > ''current_user'' in any view. The same for method ''logged_in?''. > > Now try doing the same for method ''login_required'', which is also > inside of AuthenticatedSystem module. Doesn''t work. Reads "undefined > local variable or method ''login_required''". > > Summing up, both ''logged_in?'' and ''login_required'' are inside of > Authenticated System module. ''logged_in?'' is accessible from any view, > while ''login_required'' is not. > > What''s the difference?#current_user and #logged_in? are available as helpers in your views because of these lines : def self.included(base) base.send :helper_method, :current_user, :logged_in? end The ''included'' callback (called when you do "include AuthenticatedSystem") is responsible of this, thanks to ActionController::Base.helper_method method. -- Jean-François. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
truetype
2007-Dec-30 14:25 UTC
Re: Why are some methods of library accessible, while others are not? (by the example of restful_authentication)
Thank you, Jean-François. Actually, I checked application_helper.rb before I posted here. But having found blank, I was very surprised. Didn''t know that helpers could be created the way you showed. Thanks again, Happy 2008 to you and all the community, truetype --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---