Display related records, if they exist, in Rails view Is this much logic in view is justified to check for the presence of record?

# device model
class Device &lt; ApplicationRecord
  validates :abbr, uniqueness: { case_sensitive: false }, presence: true
  validates :name, presence: true

  def abbr=(value)
    self[:abbr] = value.to_s.strip
  end
end


Here is the code for DeviceVendor that also saves abbr column of Device to uniquely identify the device:

# model code 
class DeviceVendor &lt; ApplicationRecord
  validates :vendor, uniqueness: {scope: :device}
end

# controller code
def index
  @device_vendors = DeviceVendor.order(:device, :vendor)
end

# view code
&lt;% @device_vendors.each do |device_vendor| %&gt;
  &lt;% device = Device.where(abbr: device_vendor.device).first %&gt;
  &lt;% vendor = Vendor.where(abbr: device_vendor.vendor).first %&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;%= device.name if device %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= vendor.name if vendor %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Show', device_vendor %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to 'Edit', edit_device_vendor_path(device_vendor) %&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;% end %&gt;


What is the rails way to do this?
There's a lot of ways to check the presence of an object, i prefer to use try :

device.try(&amp;:name)