options_for_select选择的值不起作用

我有一个projectuser数据的表单,但是当我编辑projectuser时,所选的projectuser保持为空,出了什么问题? 这是代码:

= f.select :user_id, options_for_select(@users.map{ |u| [u.full_name, u.id] }, selected: @projectuser.full_name), include_blank: true 

Google:options_for_select,第一个结果:

 (...) options_for_select(container, selected = nil) public (...) (million examples) 

所以你不应该通过selected: something ,但只是something 。 此外,这个东西需要选择值,而不是文本:

 = f.select :user_id, options_for_select(@users.map{ |u| [u.full_name, u.id] }, @projectuser.id), include_blank: true 

按照你的回答我写了这样的东西。

 f.select :relationship, options_for_select( Relationship.all.map{|rel| [rel.name, rel.id]}, @order.relationship.id.to_s ), prompt: 'Please select', class: "form-control" 

我在nil错误上得到一个被调用的id,因为这是试图设置一个尚不存在的选定值。 我在rails 3.13上我的Order模型与Relationship模型有belongs_to关系

谢谢你的帮助。