Ruby on Rails
Wednesday, July 8, 2015
Why do you not use
if current_user.roleid == 1
to test if the logged in user is admin or not?
Same result.
When I logged in as admin, this is the result
******************************************
The roleid is ["1"] executed in else part
******************************************
When I logged in as non admin, this is the result
******************************************
The roleid is ["2"] executed in else part
******************************************
Why both are executing in the else part?
This is the code I modified in sessions_controller.rb
if current_user.roleid == 1
flash.now[:info] = 'You are logged in as Admin and your roleid is #{role}'
redirect_to dashboard_index_path
puts "*******************************************************************************************************"
puts "The roleid is #{rolea} executed in if part"
puts "*******************************************************************************************************"
else
flash.now[:danger] = 'For some reason you are not recognized as Admin and the roleid is #{role}'
redirect_to dashboard_index_path
puts "*******************************************************************************************************"
puts "The roleid is #{role} executed in else part"
puts "*******************************************************************************************************"
end
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0b496cc5-3d67-4585-9fa8-8daf75b0b722%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment