簡體   English   中英

為什么我的視圖顯示活動記錄對象?

[英]Why is my view displaying an active-record object?

我想顯示活動記錄哈希中的值,但是我只看到對象本身。

當我嘗試在視圖中顯示值時,將顯示以下內容:

#<ACTIVERECORD::RELATION:0X007F2600849018>

如果我在視圖代碼中添加.all作為哈希值,則會顯示此內容。

[#<IPSREFERENCE_SYSTEM REF_SYSTEM_NAME: "BUGTRAQ">]

來自控制器的代碼。 我已將數據添加到@sig_info@sig_ref_info數組中以在我的視圖中使用:

  def get_sig_id(sig_sid)
    IpsSignature.where('sig_sid =?', sig_sid).first.sig_id
  end

  def get_sig_sid(sig_id)
    IpsSignature.where('sig_id =?', sig_id).first.sig_sid
  end

  def get_sig_gid(sig_id)
    IpsSignature.where('sig_id =?', sig_id).first.sig_gid
  end

  def get_sig_class_id(sig_id)
    IpsSignature.where('sig_id =?', sig_id).first.sig_class_id
  end

  def get_sig_class_name(sig_class_id)
    IpsSigClass.where('sig_class_id =?', sig_class_id).first.sig_class_name
  end

  def get_sig_name(sig_id)
    IpsSignature.where('sig_id =?', sig_id).first.sig_name
  end

  def get_ref_id(sig_id)
    IpsSig_reference.select('ref_id').where('sig_id =?', sig_id)
  end

  def get_ref_system_id(ref_id)
    IpsReference.select('ref_system_id').where('ref_id =?', ref_id)
  end

  def get_ref_system_name(ref_system_id)
    IpsReference_System.select('ref_system_name').where('ref_system_id =?', ref_system_id)
  end

  def get_ref_tag(ref_id)
    IpsReference.select('ref_tag').where('ref_id =?', ref_id)
  end

  def ips_signatures

    @sig_info = Array.new
    @sig_ref_info = Array.new

    if params[:query].present?

      signature_id = params[:query]
      sig_id = get_sig_id(signature_id)
      sig_sid = get_sig_sid(sig_id)
      sig_gid = get_sig_gid(sig_id)
      sig_class_id = get_sig_class_id(sig_id)
      sig_class_name = get_sig_class_name(sig_class_id)
      sig_name = get_sig_name(sig_id)
      sig_ref_id = get_ref_id(sig_id)
      sig_ref_id.each do |id|
        sig_ref_tag = get_ref_tag(id.ref_id)
        sig_ref_system_id = get_ref_system_id(id.ref_id)
        sig_ref_system_id.each do |sys_id|
          sig_ref_system_name = get_ref_system_name(sys_id.ref_system_id)
          @sig_ref_info += [sig_ref_system_name: sig_ref_system_name, sig_ref_tag: sig_ref_tag]
        end
      end
      @sig_info = [sig_sid:sig_sid,sig_gid: sig_gid, sig_class_name: sig_class_name, sig_name: sig_name]
    end
  end

我循環拋出@sig_ref_info@sig_info數組(查看代碼):

  <% @sig_info.each do |sig_info| %>

    <div style="color:#58585a; font-size: 24px;padding-top:50px;padding-bottom:10px;font-weight:bold">
        Signature ID:
    </div>

    <div style="color:#58585a; font-size: 20px;padding-bottom:30px;font-weight:bold;">
        <%= sig_info[:sig_sid] %>
    </div>

    <table style="border-style:none">
        <div style="color:#2a2874; font-size: 24px;padding-bottom:20px;border-style:none">
          generator id:
        </div>
    </table>

    <table style="border-style:none">
        <div style="color:#2a2874; font-size: 20px;padding-bottom:20px;border-style:none">
          <%= sig_info[:sig_gid] %>
        </div>
    </table>

      <table style="border-style:none">
        <div style="color:#2a2874; font-size: 24px;padding-bottom:20px;border-style:none">
          class:
        </div>
      </table>

      <table style="border-style:none">
        <div style="color:#2a2874; font-size: 20px;padding-bottom:20px;border-style:none">
          <%= link_to sig_info[:sig_class_name], '/ips_alert_classes?query='+ sig_info[:sig_class_name].to_s %>
        </div>
      </table>

      <table style="border-style:none">
        <div style="color:#2a2874; font-size: 24px;padding-bottom:20px;border-style:none">
          signature name:
        </div>
      </table>

      <table style="border-style:none">
        <div style="color:#2a2874; font-size: 20px;padding-bottom:20px;border-style:none">
          <%= sig_info[:sig_name] %>
        </div>
      </table>

<% end %>

        <table style="border-style:none">
            <div style="color:#2a2874; font-size: 24px;padding-bottom:20px;border-style:none">
                references:
            </div>
        </table>

  <% @sig_ref_info.each do |ref_info| %>

        <table style="border-style:none">
            <div style="color:#2a2874; font-size: 20px;padding-bottom:20px;border-style:none">
                <%= ref_info[:sig_ref_system_name] %> | <%= ref_info[:sig_ref_tag] %>
            </div>
        </table>

  <% end %>

ref_info循環是我遇到的問題,其余顯示都很好。 我希望從活動記錄關系對象中提取的鍵是REF_SYSTEM_NAME:鍵,如何在我的視圖的do塊中提取此鍵?

我重建了有效記錄的關系(在黑客的幫助下),並且現在可以正常工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM