2013-03-20 164 views
-1

我有一個佔位符文本的窗體。我希望能夠使其中的一部分變得動態。這似乎很簡單,但我無法弄清楚。我錯過了什麼?是否可以將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.' 

但是,當我這樣做,它通過分享你所讀文字「幫助他人」我學到了<%= @ major.name%> major。「

回答

1

問題是,如果你把你的字符串放在單引號內,它將被逐字地顯示出來。用雙引號將#{}內的結果正確解析。

試試這個:

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

謝謝!我也試過#{@major.name},但是我忽略了雙引號。非常感謝! – lflores 2013-03-20 22:04:47

相關問題