I want to compare two values given
<% if (current_user.role.title).eql?( "Test") %>
but this comparison doesn’t seem to work at all. I checked for the value in current_user.role.title and it prints “Test” ; but when i compare it inside the html page this fails. I also tried doing
<% if current_user.role.title == "Test" %>
but it doesnt work!! The value current.role.title is stored as a Varchar in the database.
To expand on my comment, it looks like you managed to get a trailing space in your
title. You’re getting-Test -when you try:and
current_user.role.bytes.countis 5 so it is just a plain space (or possibly a tab) rather than some Unicode confusion.You probably want to clean up your data before storing it with
striporstrip!and you’ll want to do the same to any data you already have.One final check would be to try this:
The trailing space also explains why your
splitapproach behaved as expected:Just
string.splitwill split (almost always) split on spaces sorole_Arrayended up looking like['Test']becausesplitwould throw away the trailing space.