Я пытаюсь «взломать» ActiveRecord_Relation для рендеринга в представлениях в Rails. Я получаю ответ, такой как:
#<ActiveRecord::Relation [#<Request id: 25803, time_inserted: "2019-07-27 17:20:17", time_modified: "2019-08-03 17:37:48", time_completed: "2019-08-03 17:37:48", disposition: "Forced Ignore", account: "301385", trans_uuid: "008326d4-b090-11e9-aead-0282b642e944", customers_identifier: "46134865dfdsaasdfs4", customers_reason: "E", customers_customer: "reveltransit", request_state: "NY", request_license: "12345678", request_lastname: "BOLLS", request_firstname: "JEFF", request_middlename: nil, request_dob: nil, request_gender: "">, #<Request id: 25919, time_inserted: "2019-07-27 17:40:17", time_modified: "2019-08-03 17:37:48", time_completed: "2019-08-03 17:37:48", disposition: "Forced Ignore", account: "301385", trans_uuid: "008326d4-b090-11e9-aead-0282b642e944", customers_identifier: "4434kjk34k3j43kk34j3", customers_reason: "E", customers_customer: "reveltransit", request_state: "NY", request_license: "12345678", request_lastname: "BOLLS", request_firstname: "JEFF", request_middlename: nil, request_dob: nil, request_gender: "">, #<Request id: 26069, time_inserted: "2019-07-27 18:00:20", time_modified: "2019-08-03 17:37:48", time_completed: "2019-08-03 17:37:48", disposition: "Forced Ignore", account: "301385", trans_uuid: "008326d4-b090-11e9-aead-0282b642e944", customers_identifier: "461348652f19ffc4901efc8e31c4", customers_reason: "E", customers_customer: "reveltransit", request_state: "NY", request_license: "12345678", request_lastname: "BOLLS", request_firstname: "JEFF", request_middlename: nil, request_dob: nil, request_gender: "">]>
Моя модель выглядит следующим образом:
class Request < ApplicationRecord
establish_connection(:development)
self.table_name = "incoming"
def self.search(search)
self.where(:trans_uuid => search)
end
end
Метод поиска в моем контроллере:
def search
results = Request.search(params[:search])
@records = results.pluck(:trans_uuid)
byebug
end
и Просмотры:
<%= form_with url: requests_search_path, method: :get do |form| %>
<%= form.text_field :search %>
<%= form.submit 'Search' %>
<% end %>
<h3><u>Search Results</u></h3><br />
<h4><%= @records.map { |record| record } %></h4>
Невозможно получить его для визуализации в поле зрения, потому что это всегда массив. Если я пытаюсь перебрать его, я получаю ошибку no method
.