gpt4 book ai didi

ruby-on-rails - Rails 4 simple_form collection_select

转载 作者:行者123 更新时间:2023-12-03 10:19:44 24 4
gpt4 key购买 nike

如何将以下内容翻译成简单的形式?

<%= form_for(@bill) do |f| %>

<%= f.label :location_id %>
<%= f.collection_select(:location_id, @locations, :id, :location_name,
{:selected => @bill.location_id}) %>

我不能使用简单的关联,因为 @locations 是 where 查询的结果。

最佳答案

尝试这个

<%= simple_form_for @bill do |f| %>
<%= f.input :location,:collection => @locations,:label_method => :location_name,:value_method => :id,:label => "Location" ,:include_blank => false %>
<%= f.button :submit %>
<%end%>

希望这有帮助

关于ruby-on-rails - Rails 4 simple_form collection_select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17702426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com