Rails 4 simple_form collection_select [英] Rails 4 simple_form collection_select
本文介绍了Rails 4 simple_form collection_select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将以下内容翻译成简单的形式?
How do I translate the following to simple form?
<%= form_for(@bill) do |f| %>
<%= f.label :location_id %>
<%= f.collection_select(:location_id, @locations, :id, :location_name,
{:selected => @bill.location_id}) %>
我不能使用简单的关联,因为 @locations 是 where 查询的结果.
I can't use a simple association because @locations is the result of a where query.
推荐答案
试试这个
<%= 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%>
希望对您有帮助
这篇关于Rails 4 simple_form collection_select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文