【发布时间】:2014-08-30 12:13:21
【问题描述】:
如何在视图中指定仅在描述存在时才显示保存的标题?
:input_html => { :value => "#{@description.title}" }
【问题讨论】:
标签: html ruby-on-rails ruby ruby-on-rails-4 haml
如何在视图中指定仅在描述存在时才显示保存的标题?
:input_html => { :value => "#{@description.title}" }
【问题讨论】:
标签: html ruby-on-rails ruby ruby-on-rails-4 haml
:input_html => { :value => "#{@description.try(:title)}" }
你也可以这样写:description.title if description
但看起来您正在使用simple_form gem,在这种情况下,f.input :description, input_html: { class: 'special' } 之类的东西应该会自动设置值(如果存在)。
【讨论】: