Search code examples
ruby-on-railsrubyconcatenationhaml

Ruby on Rails: error on concatenating string datatype field and boolean datatype field


I'm working on a Rails HAML View and I'm trying to display together two fields: the first one is String datatype and the other one is Boolean datatype, I'm trying with this line of code:

      %td=students.name + " " + students.status ? '(Passed)' : ''

As you can see I'm using a ternary operator to cast true to Passed and false to blank.

However, I'm getting this error:

error_message

Also, if I avoid ternary operator I got the same output error.

My question is: how can I cast these two fields and at the same time show "passed" if it is true?

Thanks a lot


Solution

  • try this:

    %td=students.name + " " + (students.status ? '(Passed)' : '' )