【问题标题】:Condition statement in the view error视图错误中的条件语句
【发布时间】:2014-08-30 12:13:21
【问题描述】:

如何在视图中指定仅在描述存在时才显示保存的标题?

:input_html => { :value => "#{@description.title}" }

【问题讨论】:

    标签: html ruby-on-rails ruby ruby-on-rails-4 haml


    【解决方案1】:
    :input_html => { :value => "#{@description.try(:title)}" }
    

    你也可以这样写:description.title if description

    但看起来您正在使用simple_form gem,在这种情况下,f.input :description, input_html: { class: 'special' } 之类的东西应该会自动设置值(如果存在)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 2017-12-15
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      相关资源
      最近更新 更多