On 8 July 2015 at 12:08, Padmahas Bn <[email protected]> wrote: >> Why do you not use >> if current_user.roleid == 1 >> to test if the logged in user is admin or not? >> > Hey colin ignore my last message. I just tried by inserting 1 in between > quotes like this and it worked!! > if current_user.roleid == "1". > > May be it was considering 1 as Boolean value or something.
Check the field type you specified for roleid in the database. I guess you have it as a string not an integer, hence the need to check for string "1" not number 1. Now probably you want to introduce a method in User def admin? roleid == "1" end then you can say if current_user.admin? Colin -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuQi2wHZCRxb3gEwbdDtinBYsdpHgMArimqi51mpkqKWw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

