Sinatra错误增加了不确定的问题

时间:2018-04-13 01:44:28

标签: html ruby-on-rails ruby html5 sinatra

我遇到的问题是没有将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

1 个答案:

答案 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_psausage_p和{{1} }}。根据您上面提到的变量定义,它必须是fruit_ppeporinisausage

另外 - 我讨厌成为那个人,但你可能想对此进行拼写检查 - 你可能想要fruit而不是surnamesirname而不是{{1} }:)