我遇到的问题是没有将nil隐式转换为String并且我在sinatra上如此困惑就是在重定向' / final'和位置是一个+我真的需要知道什么问题,因为这是一个学校作业,我有需要在星期一转入
require "sinatra"
get '/' do
erb :namesex
end
post '/namesex' do
firstname = params[:firstname]
lastname = params[:lastname]
sirname = params[:sirname]
redirect '/pizza?firstname=' + firstname + '&lastname=' + lastname +
'&sirname=' + sirname
end
get '/pizza' do
firstname = params[:firstname]
lastname = params[:lastname]
sirname = params[:sirname]
erb :pizza, :locals => {:firstname => firstname, :lastname => lastname,
:sirname => sirname}
end
post '/pizza' do
firstname = params[:firstname]
lastname = params[:lastname]
sirname = params[:sirname]
cheese_p = params[:cheese_p]
peporini_p = params[:peporini_p]
sausage_p = params[:sausage_p]
fruit_p = params[:fruit_p]
submit = params[:submit]
redirect '/final?firstname=' + firstname + '&lastname=' + lastname +
'&sirname=' + sirname + '&cheese_p=' + cheese_p + '&peporini_p=' +
peporini_p + '&sausage_p=' + sausage_p + '&fruit_p=' + fruit_p + '&submit' +
submit
end
get '/final' do
firstname = params[:firstname]
lastname = params[:lastname]
sirname = params[:sirname]
cheese = params[:cheese]
peporini = params[:peporini]
sausage = params[:sausage]
fruit = params[:fruit]
erb :final, :locals => {:firstname => firstname, :lastname => lastname,
:sirname => sirname, :cheese_p => cheese_p, :peporini_p => peporini_p,
:sausage_p => sausage_p, :fruit_p => fruit_p, :submit => submit}
end
答案 0 :(得分:2)
您的/final
路线如下所示:
firstname = params[:firstname]
lastname = params[:lastname]
sirname = params[:sirname]
cheese = params[:cheese]
peporini = params[:peporini]
sausage = params[:sausage]
fruit = params[:fruit]
erb :final, :locals => {
:firstname => firstname,
:lastname => lastname,
:sirname => sirname,
:cheese_p => cheese_p,
:peporini_p => peporini_p,
:sausage_p => sausage_p,
:fruit_p => fruit_p,
:submit => submit
}
您传递到erb :final
的三个变量在上面的区块中不存在 - peporini_p
,sausage_p
和{{1} }}。根据您上面提到的变量定义,它必须是fruit_p
,peporini
和sausage
。
另外 - 我讨厌成为那个人,但你可能想对此进行拼写检查 - 你可能想要fruit
而不是surname
和sirname
而不是{{1} }:)