我如何访问多个 post 上的参数或获取
how do i access a param on more than one post or get
我想在我的 post /'startgames' 中询问某人的名字,并希望能够在我所有的 post 和 gets 中使用它,但我遇到了任何问题帮助将不胜感激....
我刚刚开始学习 ruby 甚至更多,所以即使是 sinatra,我也为 comp 和在线制作了一个 tictactoe 游戏,并且我从一开始就一直在为计算机本身编写这个游戏,并且我在学习新内容时不断重构东西所以请不要对我太苛刻因为我确定我让它变得比需要的更复杂但是它到目前为止工作
require 'sinatra'
# require_relative "trippy_game_functions.rb"
# trippy = Joestrippygame.new
get '/startgames' do
answerphone = params[:playgame]
erb :startgame, :locals => {:message1 => "Welcome To Joe's Games. Click the game you wish to play ."}
end
post '/startgames' do
answerphone = params[:playgame]
@playername = @params[:name]
if answerphone == "Joe's Trippy Adventure Game"
erb :trippygame1, :locals => {:message1 => "#{@playername} Chose to Play Joe's Trippy Adventure Game."}
elsif answerphone == "Jade's Safari Adventure Game"
erb :safari1, :locals => {:message1 => "#{@playername} Chose to play Jade's Safari Adventure Game."}
else
erb :startgame, :locals => {:message1 => "Thanks For playing Have a Great Day"}
end
end
post '/answerdoor' do
answerdoor = params[:door]
@playername = @params[:name]
door = rand(2).floor
if answerdoor.include?('Yes') && door == 0
# erb :answerdoor, :locals => {:answerdoor => "#{playername} Decides to get up and answer the door", :answerdoor2 => " #{playername} your in Luck It's Your good buddy Dave." }
erb :davehere, :locals => {:daveishere => "Your in Luck ,It's Your Good Buddy Dave.", :message1 => "Whats up #{@playername} #{params[:name]} I'm Thinking about hitting the club up wanna go? "}
elsif answerdoor.include?('Yes') && door == 1
# erb :answerdoor, :locals => {:answerdoor => "#{playername} Decides to get up and answer the door", :answerdoor2 => " Oh No its The cops." }
redirect to ('/police')
elsif answerdoor.include?('No') && door == 0
erb :answerdoorno, :locals => {:answerdoor => "#{@playername} Decides not to answer the door, but it dosen't Really matter cause Dave walks in anyways."}
elsif answerdoor.include?('No') && door == 1
# erb :answerdoorno, :locals => {:answerdoor => "#{playername} Decides not to answer the door, but it dosen't Really matter cause its the cops and the bust in."}
redirect to ('/police')
end
end
get '/police' do
@playername = @params[:name]
erb :police, :locals => {:msg1 => "Fuck I'ts the cops" ,:arrested => "Well damn man. That sucks #{@playername}...." }
end
我想在我的 post /'startgames' 中询问某人的名字,并希望能够在我所有的 post 和 gets 中使用它,但我遇到了任何问题帮助将不胜感激....
我刚刚开始学习 ruby 甚至更多,所以即使是 sinatra,我也为 comp 和在线制作了一个 tictactoe 游戏,并且我从一开始就一直在为计算机本身编写这个游戏,并且我在学习新内容时不断重构东西所以请不要对我太苛刻因为我确定我让它变得比需要的更复杂但是它到目前为止工作
require 'sinatra'
# require_relative "trippy_game_functions.rb"
# trippy = Joestrippygame.new
get '/startgames' do
answerphone = params[:playgame]
erb :startgame, :locals => {:message1 => "Welcome To Joe's Games. Click the game you wish to play ."}
end
post '/startgames' do
answerphone = params[:playgame]
@playername = @params[:name]
if answerphone == "Joe's Trippy Adventure Game"
erb :trippygame1, :locals => {:message1 => "#{@playername} Chose to Play Joe's Trippy Adventure Game."}
elsif answerphone == "Jade's Safari Adventure Game"
erb :safari1, :locals => {:message1 => "#{@playername} Chose to play Jade's Safari Adventure Game."}
else
erb :startgame, :locals => {:message1 => "Thanks For playing Have a Great Day"}
end
end
post '/answerdoor' do
answerdoor = params[:door]
@playername = @params[:name]
door = rand(2).floor
if answerdoor.include?('Yes') && door == 0
# erb :answerdoor, :locals => {:answerdoor => "#{playername} Decides to get up and answer the door", :answerdoor2 => " #{playername} your in Luck It's Your good buddy Dave." }
erb :davehere, :locals => {:daveishere => "Your in Luck ,It's Your Good Buddy Dave.", :message1 => "Whats up #{@playername} #{params[:name]} I'm Thinking about hitting the club up wanna go? "}
elsif answerdoor.include?('Yes') && door == 1
# erb :answerdoor, :locals => {:answerdoor => "#{playername} Decides to get up and answer the door", :answerdoor2 => " Oh No its The cops." }
redirect to ('/police')
elsif answerdoor.include?('No') && door == 0
erb :answerdoorno, :locals => {:answerdoor => "#{@playername} Decides not to answer the door, but it dosen't Really matter cause Dave walks in anyways."}
elsif answerdoor.include?('No') && door == 1
# erb :answerdoorno, :locals => {:answerdoor => "#{playername} Decides not to answer the door, but it dosen't Really matter cause its the cops and the bust in."}
redirect to ('/police')
end
end
get '/police' do
@playername = @params[:name]
erb :police, :locals => {:msg1 => "Fuck I'ts the cops" ,:arrested => "Well damn man. That sucks #{@playername}...." }
end