Html 为什么索引视图要打印整个表?

Html 为什么索引视图要打印整个表?,html,ruby-on-rails,sqlite,model-view-controller,erb,Html,Ruby On Rails,Sqlite,Model View Controller,Erb,这个应用程序包含一个要提交的表单,目前我正在尝试打印表中的几行。这是可行的,但不幸的是,我还得到了整个数据库表属性的单个长字符串。我所写的代码(我相信)中没有任何东西会导致这种情况。我担心这是一些看不见的rails魔法,任何洞察都会很棒 控制员: class StudentsController < ApplicationController def new @student = Student.new end def create student_map

这个应用程序包含一个要提交的表单,目前我正在尝试打印表中的几行。这是可行的,但不幸的是,我还得到了整个数据库表属性的单个长字符串。我所写的代码(我相信)中没有任何东西会导致这种情况。我担心这是一些看不见的rails魔法,任何洞察都会很棒

控制员:

class StudentsController < ApplicationController
  def new
    @student = Student.new
  end

  def create
     student_map = {"student_id" => params[:student_id], "student_name" => params[:student_name],
  "major" => params[:major], "minor" => params[:minor], "other_information" => params[:other_information], 
  "class_year_id" => params[:class_year_id], "hours_st" => params[:hours], "qr_id" => qr_id,}

     if (newStudentRow.save)
        redirect_to action: 'index'
     else
        render action: 'new'
     end
  end

  def index
     @students = Student.all
  end
end
class StudentsControllerparams[:学生id],“学生名称”=>params[:学生名称],
“主要”=>参数[:主要],“次要”=>参数[:次要],“其他信息”=>参数[:其他信息],
“类年id”=>参数[:类年id],“小时数”=>参数[:小时],“类年id”=>类年id,}
如果(newStudentRow.save)
将_重定向到操作:“索引”
其他的
渲染操作:“新建”
结束
结束
def索引
@学生
结束
结束
索引视图:

<h1>Students#index</h1>
<p>Find me in app/views/students/index.html.erb</p>

<table>
    <thead>
        <tr>
            <th>Student Name</th>
            <th>ID</th>
        </tr>
    </thead>
    <tbody>
    <%= @students.each do |s| %>
        <tr>
        <td><%= s.student_name %></td>
        <td><%= s.student_id %></td>
    </tr>
    </tbody>
    <% end %>
</table>
学生索引
在app/views/students/index.html.erb中查找我

学名 身份证件
输入数据并提交表单后,此链接显示以下输出:

谢谢你的帮助

变化:

<%= @students.each do |s| %>

为此:

<% @students.each do |s| %>

在Ruby中,
each
为每个元素执行块并返回数组。让
=
输出数组,这就是您看到长字符串的原因。

更改:

<%= @students.each do |s| %>

为此:

<% @students.each do |s| %>

在Ruby中,
each
为每个元素执行块并返回数组。让
=
输出数组,这就是您看到长字符串的原因。

更改:

<%= @students.each do |s| %>

为此:

<% @students.each do |s| %>

在Ruby中,
each
为每个元素执行块并返回数组。让
=
输出数组,这就是您看到长字符串的原因。

更改:

<%= @students.each do |s| %>

为此:

<% @students.each do |s| %>

在Ruby中,
each
为每个元素执行块并返回数组。让
=
输出数组,这就是为什么会看到长字符串