如何阻止该属性数组在我的视图中显示? [英] How to stop this array of attributes from showing in my view?

查看:75
本文介绍了如何阻止该属性数组在我的视图中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个令人烦恼的问题,我的视图不断显示对象属性的数组!我的子菜单假设以树形形式显示类别,该类别有效,但它也显示了此烦人的数组!

I have an annoying problem where my view keeps displaying an array of my object's attributes! My submenu is suppose to show categories in a tree form, which works, but it also shows this annoying array!


[< #Category id:26,标题: subtest,描述:测试中的测试,testception,created_at: 2015-03-01 03:15:29,updated_at: 2015-03-03 01:08:09 ,祖先: 6/24>]

[ <#Category id: 26, title: "subtest", description: "a test within a test, testception", created_at: "2015-03-01 03:15:29", updated_at: "2015-03-03 01:08:09", ancestry: "6/24">]

[<#类别ID:24,标题:测试,描述:不要惊慌,此只是一个测试。,created_at: 2015-03-01 02:06:35,updated_at: 2015-03-03 01:07:52,祖先: 6>]

[ <#Category id: 24, title: "Test", description: "No not be alarmed, this is only a test.", created_at: "2015-03-01 02:06:35", updated_at: "2015-03-03 01:07:52", ancestry: "6">]

我绝对不希望用户看到此内容。如何摆脱它?

I definately don't want the user to see this. How do I get rid of it??

Show.html.erb视图:

Show.html.erb view:

<div id="submenu">
  <%= render 'submenu_cats', categories: @category.root.children %>
</div>

_submenu猫部分:

_submenu cats partial:

<ul>
  <%= categories.each do |category| %>
    <li>
        <%= link_to_unless_current category.title, category_path %>
        <%= render 'submenu_cats', categories: category.children if category.children.present? %>
    </li>
  <% end %>

使用:Rails 4.2,Ruby 2.1.5,祖先宝石

Using: Rails 4.2, Ruby 2.1.5, Ancestry Gem

推荐答案

请勿使用...

<%= categories.each do |category| %>

使用

<% categories.each do |category| %>

当您使用<%= 时,您正在输出表达式的结果。 categories.each 的结果是 categories ,即正在输出的数组。您不想输出它,因此使用<%评估Ruby而不输出结果。

When you use <%=, you're outputting the result of the expression. The result of categories.each is categories, the array that is being output. You don't want to output it, so use <% to evaluate the Ruby without outputting the results.

这篇关于如何阻止该属性数组在我的视图中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆