0
這是我們要添加到動態視圖的局部形式_standards.html.erb:如何在rails 3.1.0中動態添加選擇框?
<p><%= f.association :standards, :collection => Standard.active_std.all(:order => 'name'), :label_method => :name, :value_method => :id :include_blank => true %></p>
這裏是視圖形式本身_form_new.html.erb這就要求_standards.html.erb:
<%= simple_form_for @rfq do |f| %>
<div id="std">
<%= render :partial => 'standards/standards', :collection => @rfq.standards, :locals => { :f => f } %>
</div>
<%= link_to_function("Add std", nil) do |page| %>
page.insert_html :bottom, 'std', :partial => 'standards/standards', :object => @rfq.standards.build
<% end %>
<%= f.button :submit, 'Save' %>
<% end %>
此解決方案不起作用,因爲link_to_function沒有對加載_standards.html.erb的點擊做出反應。這個解決方案似乎過時了,並且在rails 3.1.0中不起作用。我想知道是否有其他解決方案將動態內容添加到rails 3.1.0中的視圖頁面。如果你這樣做,請不要猶豫,發佈。謝謝。
動態意義不刷新頁面? – iwasrobbed 2012-01-14 16:10:50
我的意思是通過請求添加內容,例如通過加載_standards.html.erb來單擊添加按鈕來添加選擇框。 – user938363 2012-01-14 16:32:40
用於動態更新頁面的AJAX請求在Rails 3中完成了一點不同。您應該看這個:http://railscasts.com/episodes/205-unobtrusive-javascript – iwasrobbed 2012-01-14 19:37:06