gpt4 book ai didi

ruby-on-rails - 为什么 rails 将数据转储到每个页面上

转载 作者:数据小太阳 更新时间:2023-10-29 07:57:07 25 4
gpt4 key购买 nike

我有一个名为 list_controller 的简单 Controller ,其索引基本上可以执行

def index
@lists = List.all
end

然后我有一个名为 index.html.haml 的 View ,它看起来像:

%h1 My lists
= @lists.each do |list|
.row-fluid
%h2= list.title
%p= list.description
%hr
= link_to "New list", new_list_url

这有效并呈现,但在我的列表底部似乎是列表对象的 ruby 打印,在这种情况下是一个漂亮的大丑陋:

[#<List id: 1, title: "Petes todo list", description: "This is petes main list, all sorts of good stuff", created_at: "2012-03-26 21:42:57", updated_at: "2012-03-26 21:42:57">, #<List id: 2, title: "Petes work list", description: "A list for petes work stuff", created_at: "2012-03-26 22:09:50", updated_at: "2012-03-26 22:09:50">]

为什么会这样?我该如何阻止它?

最佳答案

你正在输出 each 的结果,改变:

= @lists.each do |list|

到:

- @lists.each do |list|

Haml 文档:=对比-

关于ruby-on-rails - 为什么 rails 将数据转储到每个页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com