得到这个的最短途径是什么?

时间:2016-07-21 05:40:38

标签: ruby-on-rails-4

最短/最好/最好的方法是什么?其中f是包含Customer和belongs_to customer_contract_id模型的CustomerContact模型的表单别名。

<%= f.object.customer_contact.blank? ? '':f.object.customer_contact.name %>

这不起作用

<%= f.object.customer_contact.name ||= '' %>

我为任何困惑/挫折道歉。我感谢你能得到的任何帮助!

1 个答案:

答案 0 :(得分:2)

你能这样试试吗?

<%= f.object.customer_contact.present? ? f.object.customer_contact.name : ''  %>

请注意:与两个输出之间的空格。 .present?.blank?

相反

对于将来的参考,我认为这个表对你有所帮助。

enter image description here

此表的积分应转到 Sibevin Wang

希望这有帮助吗?

相关问题