有人可以帮助我弄清楚为什么下面的简单代码只是在填写表格之后不会显示表格内容(或任何内容)。提交?我想从头开始练习Sinatra的动态表单,镜像一些现有的工作代码。但是我的工作不起作用。
fam.rb(下)
require 'sinatra'
get '/fam_form' do
family_names = %w(ma pa sis bro dog cat)
erb :fam_form
end
post '/fam_list' do
@ma = params[:ma]
@pa = params[:pa]
@sis = params[:sis]
@bro = params[:bro]
@dog = params[:dog]
@cat = params[:cat]
erb :fam_list
end
fam_form.erb(下)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>family form</title>
</head>
<body>
<form method="POST" action="/fam_list">
<p>Ma: <input type="text" name="ma"></p>
<p>Pa: <input type="text" name="pa"></p>
<p>Sis: <input type="text" name="sis"> </p>
<p>Bro: <input type="text" name="bro"> </p>
<p>Dog: <input type="text" name="dog"></p>
<p>Cat: <input type="text" name="cat"></p>
<input type="submit" name="submit" value="submit" id="submit">
</form>
</body>
</html>
fam_list.erb(下方)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Fam List</title>
</head>
<body>
<h1>My Family Members </h1>
<p>Ma <%= @ma %> </p>
<p>Pa <%= @pa %> </p>
<p>Sis <%=@sis %> </p>
<p>Bro <%=@bro %> </p>
<p>Dog <%=@dog %> </p>
<p>Cat <%=@cat %> </p>
</body>
</html>