John Smith February 2016

Getting the if statement in HAML

I'm trying to make an if statement in HAML and it just keeps erroring out. Any ideas how I can get this to work. Here's what I have been trying:

f.text_field :description, class: 'field-input', @payment_type == 'flat' ? 'currency-format'=> true : 'currency-format' => false

I've defined payment_type, but it is erroring out putting red lines on the



true : //EXPECTED :/ or ruby injection

Am I doing this right?

Basically I am wanting to say:

If payment_type ==flat
    currency-format = true
    currency-format = false


Oleg Sobchuk February 2016


currency_format = @payment_type == 'flat' ? true : false
f.text_field :description, 'currency-format' => currency_format, class: 'field-input'

Oleander February 2016

Set the value for currency-format to (@payment_type == 'flat'), which is true or false.

f.text_field :description, class: 'field-input', 'currency-format' => (@payment_type == 'flat')

infused February 2016

Move the conditional logic into the value assignment for currency-format:

f.text_field :description, class: 'field-input', 'currency-format' => (@payment_type == 'flat')

Post Status

Asked in February 2016
Viewed 1,124 times
Voted 13
Answered 3 times


Leave an answer