I have what I feel is a standard habtm association to manage
user/roles/permissions. However, I’m having a small problem wondering
why “.include?” isn’t working like I thought it should.
I’m attempting to use this to determine whether a user has access to a
particular permission:
if session[:user].role.permissions.include?(‘Lead List’)
do something
end
If I call session[:user].role.permissions.inspect I get this:
[#“Lead List”, “role_id”=>“1”, “permission_id”=>“1”, “id”=>“1”}>,
#“Purchase Orders”, “role_id”=>“1”, “permission_id”=>“4”, “id”=>“4”}>,
#“Quotes”, “role_id”=>“1”, “permission_id”=>“5”, “id”=>“5”}>,
#“Invoices”, “role_id”=>“1”, “permission_id”=>“6”, “id”=>“6”}>]
But the “include?” returns false.
If I modify the condition, to the following, it works:
session[:user].role.permissions.collect{|p| p.name }.include?(‘Lead
List’)
I’m okay with it working using the latter example, but I was wondering
if there’s something I haven’t done to make the first example (minus the
.collect) not work like I thought it would.
Any pointers would be appreciated.
Cheers,
Bill