Ruby on rails 无法理解select_标记如何在rails 4中工作?

Ruby on rails 无法理解select_标记如何在rails 4中工作?,ruby-on-rails,Ruby On Rails,我在rails中有以下代码 <%= select_tag 'profile', (options_from_collection_for_select(@profiles, :id, :name, @dealer.profileid.to_i))%> 我该怎么做???根据 将产生 <select id="profile" name="profile"> <option value="CM Profile">CM Profile&

我在rails中有以下代码

<%= select_tag 'profile', (options_from_collection_for_select(@profiles, :id, :name, @dealer.profileid.to_i))%>    
我该怎么做???

根据

将产生

<select id="profile" name="profile">         
  <option value="CM Profile">CM Profile</option>   
  <option value="Admin Profile">Admin Profile</option>     
 </select>

厘米剖面
管理配置文件

您可以使用选项来选择和手动形成选项

<%=select_tag "profile", options_for_select(@profiles.map{|p| [p.name,p.id]})%>

两个答案都没有解决我的问题。但当我更改代码时,它对我有效。
变化是,

以前我写过这样的代码

@profile = Profile.select("id ,name").where("dealertype = ?","2").all
当我迭代这个对象时,打印的id和名称都是一样的

现在我改成

@profile = Profile.select("id as profileid,name").where("dealertype = ?","2").all
现在在本例中,当我迭代这个对象并打印id和name时,值是正确的 与上述代码不同

现在在
中选择标签

<%= select_tag 'profile', (options_from_collection_for_select(@profiles, :profileid, :name, @dealer.profileid.to_i))%>
但我不知道我什么时候迭代

@profile = Profile.select("id ,name").where("dealertype = ?","2").all 

id和name的值都相同。

:我的问题很清楚。当我从其他表获取数据时,同样的代码也在工作。但对于这一点,它不起作用。它将取决于表模式还是基于语法,比如语法中的:id,:name?这没什么关系。语法已经试过了,很有效。我改了,试试这个。
@profile = Profile.select("id ,name").where("dealertype = ?","2").all
@profile = Profile.select("id as profileid,name").where("dealertype = ?","2").all
<%= select_tag 'profile', (options_from_collection_for_select(@profiles, :profileid, :name, @dealer.profileid.to_i))%>
  <select id="profile" name="profile">         
       <option value="1">CM Profile</option>   
       <option value="2">Admin Profile</option>     
   </select>
@profile = Profile.select("id ,name").where("dealertype = ?","2").all