我有一个带有已注册天线的表,我想将它们与访问控制相关联,每个天线只能有一个访问控制,但是访问控制可以有很多天线,我想仅用没有安装在控件访问权限中,但我不知道该怎么做。这是我到目前为止的内容:
module Admin::AntennaReaderRfidsHelper
def antennas_for_select
antenas_rfid = AntennaReaderRfid.all
antenas_installed = AntennaInstalled.all
antenas_rfid.map do | antena |
antenas_installed.map do | instalada |
if antena.id != instalada.antenna_reader_rfid_id
puts antena.id
else
puts antena.id
end
end
end
end
end
<%= f.select(:antenna_reader_rfid_id, antennas_for_select, { include_blank: '' }, { class: 'form-control' }) %>
答案 0 :(得分:1)
假设name
是AntennaReaderRfid
中的column_name
在controller#action
中@options_antennas_for_select = AntennaReaderRfid.where
.not("id IN (?)", AntennaInstalled.pluck(:antenna_reader_rfid_id))
.pluck(:name, :id)
可见
<%= f.select(:antenna_reader_rfid_id, @options_antennas_for_select, {prompt: "Select"}, {class: 'form-control', required: true}) %>