是否可以将ERB放入simple_form占位符字符串中?

时间:2013-03-20 21:28:33

标签: ruby-on-rails ruby-on-rails-3 erb simple-form

我有一个包含占位符文本的表单。我希望能够让它成为动态的一部分。看起来很简单,但我无法弄清楚。我错过了什么?

以下是表格:

<%= simple_form_for([@reviewable, @review]) do |f| %>
  <%= f.error_notification %>
  <div class="form-inputs">
    <%= f.input :review, :input_html => { :class => "span4", :rows => 10 },
                label: false,                                
                placeholder: 'Help others by sharing what you\'ve learned as a major.' %>
  </div>
  <div class="modal-footer">
    <button class="btn cancel-modal-review" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <%= f.submit 'Share My Review', :class => "submit-feedback" %>
  </div>
<% end %>

我希望占位符文本按以下方式阅读:

placeholder: 'Help others by sharing what you\'ve learned as a <%= @major.name %> major.'

但是,当我这样做时,它会直接显示“通过分享你所学到的&lt;%= @ major.name%&gt; major来帮助他人。”

1 个答案:

答案 0 :(得分:1)

问题在于,如果将字符串放在单引号中,它将按字面显示。使用双引号,#{}内的结果将被正确解析。

试试这个:

placeholder: "Help others by sharing what you\'ve learned as a #{@major.name} major."