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