【发布时间】:2015-07-27 14:59:31
【问题描述】:
这个应用程序包含一个要提交的表单,目前我正在尝试打印几行表格。这是可行的,但不幸的是,我还得到了整个数据库表属性的一个长字符串。我编写的代码中没有任何内容(我相信)会导致这种情况。我担心这是一些看不见的轨道魔法,任何见解都会很棒!
控制器:
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
索引视图:
<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>
输入数据并提交表单后,此链接显示以下输出:
感谢您的帮助!
【问题讨论】:
标签: html ruby-on-rails sqlite model-view-controller erb