如何从 Rails 应用程序中删除意外输出? [英] How do I remove unexpected output from my Rails application?

查看:40
本文介绍了如何从 Rails 应用程序中删除意外输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Ruby on Rails,正在编写一个简单的应用程序.

I am learning Ruby on Rails and am writing a simple application.

我有一个脚手架任务和工作块.该任务有许多工作块.一个工作块属于任务.在任务视图中,我试图显示任务的关联工作块.

I have a scaffold task and workBlock. The task has many work blocks. A work block belongs to task. In the task view- show, I am trying to display the task's associated workblocks.

结果是:

>     Work Blocks:
>     
>     2
>     [#<WorkBlock id: 1, name: "2", start_time: "2014-07-23 22:52:00", end_time: "2014-07-23 22:52:00", hours_spent: nil, task_id: 33,
> created_at: "2014-07-23 22:52:26", updated_at: "2014-07-23 22:52:26">]

我不知道为什么2"以下的所有内容都出现了,也不知道如何摆脱它.

I don't know why everything below '2' is showing up, and have no idea how to get rid of it.

我也不知道这是否与所涉及的日期时间类型有关.

I also don't know if this has something to do with the datetime type involved.

代码如下:

这是在任务展示中.

<p>
</br></br>

<h2>Work Blocks: </h2>


<%= @task.work_blocks.each do |work_block| %>


<li><%=link_to work_block.name , work_block_path(work_block)%></br>


<%end%>

</p>
<p>
 <%=link_to 'Create Work Block', new_work_block_path(:task_id => @task.id)%>
</p>

这是在工作块模型中:

# == Schema Information
#
# Table name: work_blocks
#
#  id          :integer          not null, primary key
#  name        :string(255)
#  start_time  :datetime
#  end_time    :datetime
#  hours_spent :integer
#  task_id     :integer
#  created_at  :datetime
#  updated_at  :datetime
#
class WorkBlock < ActiveRecord::Base
 belongs_to :tasks
end

推荐答案

each 块替换为:

<% @task.work_blocks.each do |work_block| %>
  <li><%=link_to work_block.name , work_block_path(work_block)%></br>
<%end%>

您还使用 <%= @task.work_blocks.each...%> 输出了 每个 块的评估.

You were outputting the evaluation of each block as well by using <%= @task.work_blocks.each...%>.

看看关于 <% ... %> 和<<%> 之间的区别的答案;%= .. %> 在 rails 3 中获取有关这两个标签的详细信息.

Have a look at the answers on Difference between <% … %> and <%= .. %> in rails 3 for details on the two tags.

这篇关于如何从 Rails 应用程序中删除意外输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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