1) Is there a better function than this? def logged_in_as(role) if role == ''user'' if session[:person][:id] return true else return false end elsif role ==''admin'' if session[:person][:id] if Person.find(session[:person][:id]).role == ''admin'' return true else return false end end end end 2) My function doesn''t work even though it is in application.rb: ERROR: undefined method `logged_in_as'' for #<#<Class:0x4b9bdd4>:0x4b9bd84> VIEW: <% if logged_in_as(''user'') %> Some action <% end %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait wrote:> 1) Is there a better function than this? > > def logged_in_as(role) > if role == ''user'' > if session[:person][:id] > return true > else > return false > end > elsif role ==''admin'' > if session[:person][:id] > if Person.find(session[:person][:id]).role == ''admin'' > return true > else > return false > end > end > end > end > > 2) My function doesn''t work even though it is in application.rb: > > ERROR: > undefined method `logged_in_as'' for #<#<Class:0x4b9bdd4>:0x4b9bd84> > > VIEW: > <% if logged_in_as(''user'') %> > Some action > <% end %> >for 2), you cannot call controller methods directly from view, unless you define them as helper_method with helper_method :logged_in_as_user Bojan Mihelac -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Where does this go: helper_method :logged_in_as_user It doesn''t work in my application or People controller. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait wrote:> Where does this go: helper_method :logged_in_as_user > > It doesn''t work in my application or People controller. >it should go after defining controller, for example: class ApplicationController < ActionController::Base helper_method :tabs_menu end if it''s defined in People controller it method would be visible only in its views. best, Bojan Mihelac -- Bojan Mihelac Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com -> tools, scripts, tricks from our code lab: http://source.mihelac.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---