在我的控制器中,我试图运行一个查询以获取另一个表中未引用的所有 id,如下所示:
@vlan_numbers = ActiveRecord::Base.connection.execute("SELECT pop_vlans.id, vlan_number FROM pop_vlans WHERE pop_vlans.id NOT IN (SELECT logical_interfaces.vlan_id FROM logical_interfaces) AND pop_id != " + @pop_id.to_s)
然后在我看来,我试图collection_select
在下拉菜单中显示这些:
但我得到的错误是undefined method 'vlan_number' for [2, "2"]:Array
这些值只是查询结果的第一行。
这是所涉及的两个表的示意图:
logical_interfaces | pop_vlans
-------------------|-----------
vlan_id-------|----->id
.... | vlan_number
模型中的关系是:
pop_vlan.rb
belongs_to :logical_interface
逻辑接口.rb
# no relationship defined
更新
这是生成表单的方式:
<%= form_tag :controller => "circuit", :action => "update" %>
# other inputs
<%= select_tag options_for_select(@vlan_numbers) %>
# other inputs
</form>