在HAML中获取if语句

时间:2016-02-08 21:16:03

标签: ruby-on-rails ruby haml

我正在尝试在HAML中创建一个if语句,它只是一直出错。任何想法我怎么能让这个工作。这是我一直在尝试的:

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

我已经定义了payment_type,但错误地将红线放在

=> //RUBY EXPECTED :

true : //EXPECTED :/ or ruby injection

我这样做了吗?

基本上我想说:

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

3 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:0)

将条件逻辑移动到货币格式的值分配中:

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

答案 2 :(得分:-1)

currency-format的值设为(@payment_type == 'flat'),即truefalse

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