Rails 如何在页面的 select 表单中 select 数据表的数据

VincentJiang · 2013年11月20日 · 最后由 jxs471494539 回复于 2013年11月21日 · 2034 次阅读

假设我想在 index.html.erb 页面的 select 表单中可以 select 出数据表 users 下 name 字段下的所有数据,请问我的代码如何写?谢谢!

<%= f.collection_select :users, Users.all, :id, :username, { :prompt => 'Select a user' } %>

#1 楼 @song940 我试了,方法是可以的,谢谢你。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号