[英]Select2 populate other fields on update form RAILS
我有一個在頂部具有下拉菜單的表單,如下所示
的HTML
<div class="form-group">
<label for="psr" class="col-sm-2 col-form-label">PSR</label>
<div class="col-lg-10">
<%= select_tag(:psr, options_for_select(@psr), class:'form-control remote-select', include_blank: true, style:"width:50%" ) %>
</div>
</div>
我想將已存在的屬性從選定字段中拉到表單中,並使用戶可以通過文本框更新它們。 我無法通過選擇2文檔找到我要的東西。 使用controller / js在rails中簡單地做到這一點的最佳方法是什么?
控制器如下所示:
def index
@psr = {}
CircuitVw.where("activity_ind IN ( 'Pending', 'In Progress')").order("document_number DESC").each do | circuit |
@psr[ "#{circuit.psr} - #{circuit.customer_name}" ] = circuit.psr
end
其余的應該根據此選擇動態填充。
你可以這樣嘗試嗎:
@psr =CircuitVw.where("activity_ind IN ( 'Pending', 'In Progress')").order("document_number DESC")
<%= select_tag(:psr, options_from_collection_for_select(@psr, 'id', 'customer_name'), class:'form-control remote-select', include_blank: true, style:"width:50%" ) %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.