Ruby on Rails 在页面上查看渲染数据库信息 [英] Ruby on Rails View Rendering DB Info On Page

查看:46
本文介绍了Ruby on Rails 在页面上查看渲染数据库信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,目前正在处理一个视图,它是一个不同类别的页面.一切都正确呈现,但它也将数据库信息放在页面中.

这是我的视图代码

<div class="容器简介"><div class="卡片行"><%= @categories.each 做 |c|%><div class="card col-xs-4" %><%= image_tag c.image, :class =>猫"%><h4 class="title"><%= c.title %></h4>

<%结束%>

这是一个链接渲染页面截图

解决方案

是的,修复是:

<div class="容器简介"><div class="卡片行"><% @categories.each 做 |c|%><div class="card col-xs-4" %><%= image_tag c.image, :class =>猫"%><h4 class="title"><%= c.title %></h4>

<%结束%>

看,我从这个 <%= 中删除了 = .. 在下面的行中:

<% @categories.each 做 |c|%>

#each 方法在完成迭代后返回集合.由于这个<%=each的返回值即@categories被打印回来.但是如果你只使用 <%..,上面所有的事情都会发生,但它不会打印回对象 @categories.

I am working on a project and currently working on one of the views which is a page of different categories. Everything is rendering correctly however it's also putting the db info in the page.

Here is the code of my view

<div class="categories">
    <div class="container blurbs">
        <div class="cards row">
            <%= @categories.each do |c| %>
            <div class="card col-xs-4" %>
                <%= image_tag c.image, :class => "cat" %>
                <h4 class="title"><%= c.title %></h4>
            </div>
            <% end %>
        </div>
    </div>
</div>

Here is a link to a screenshot of rendered page

解决方案

Yes, fix is:

<div class="categories">
    <div class="container blurbs">
        <div class="cards row">
            <% @categories.each do |c| %>
            <div class="card col-xs-4" %>
                <%= image_tag c.image, :class => "cat" %>
                <h4 class="title"><%= c.title %></h4>
            </div>
            <% end %>
        </div>
    </div>
</div>

Look I removed = from this <%=.. In the below line :

<% @categories.each do |c| %>

#each method returns the collection after it completed its iterations. And due to this <%=, the return value of each which is @categories printed back. But if you use <%.. only, all above things will happen, but it wouldn't print back the object @categories.

这篇关于Ruby on Rails 在页面上查看渲染数据库信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆