Ruby on Rails 中的意外输出 [英] Unexpected output in Ruby on Rails

查看:43
本文介绍了Ruby on Rails 中的意外输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在循序渐进地学习 Ruby on Rails我从教程中的视频中得到了相当不同的输出,尽管就我所见,我的代码和教程完全相同一样.

I'm following a Ruby on Rails step-by-step and at some step I get a rather different output from the video in the tutorial, even though as far as I can see my code and the tutorial's are exactly the same.

这是相关的代码(在文件 app/views/projects/show.html.erb 中):

Here is the related code (in file app/views/projects/show.html.erb) :

<p id="notice"><%= notice %></p>

<p>
  <strong> <%= @project.name %> </strong>
</p>

<p>
  <strong>Ends at:</strong>
  <%= @project.ends_at %>
</p>

<h2>Tasks for this project </h2>

<ul>
<%= @project.tasks.each do |task| %>
<li>
<%= check_box_tag "task_done_#{task.id}", "", task.done %>
<%# <%= link_to task.title, task %> 
<%= task.title %>
</li>
<% end %>
</ul>

<%= link_to 'Edit', edit_project_path(@project) %> |
<%= link_to 'Back', projects_path %>

这是我的输出:

以及教程视频中的输出:

and the output in the tutorial video :

为什么 Ruby on Rails 输出任务对象的描述?我在我的代码中看不到任何我告诉它的地方.

Why does Ruby on Rails output the task object's description ? I cannot see any place in my code where I tell it to.

推荐答案

你需要去掉这一行的 = <%= @project.tasks.each do |task|%>

You need to remove = in this line <%= @project.tasks.each do |task| %>

<ul>
<% @project.tasks.each do |task| %>
<li>
<%= check_box_tag "task_done_#{task.id}", "", task.done %>
<%# <%= link_to task.title, task %> 
<%= task.title %>
</li>
<% end %>
</ul>

小注:

<% %> - 执行代码.

<%= %> - 打印输出.

这篇关于Ruby on Rails 中的意外输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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