Created
December 22, 2011 03:48
-
-
Save illbzo1/1508829 to your computer and use it in GitHub Desktop.
Still working on Dungeon Crawler redirection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# trying to set a method so I can use @input in other methods | |
class Input | |
def initialize(input) | |
@input = params[:input] | |
end | |
end | |
# collecting the input with a form here | |
get '/input' do | |
@input = params[:input] | |
end | |
# this is just when a user loads the page. Probably a better way to call the | |
# initial index view, but this is what we're working with so far. | |
get '/' do | |
@start_room = start_room | |
erb :start_room | |
# case @input | |
# when "go north" | |
# redirect "/dais_room" | |
# end | |
end | |
# the routing method that generates rooms based on the room method. Really cuts | |
# down on how many get /'foo' routes I had to build! | |
get '/:room' do |room_name| | |
@current_room = room_name | |
#@description = method(:dais_room).call | |
#method(:dais_room).call == dais_room | |
@description = method(room_name.to_sym).call | |
erb :room | |
case @input | |
when "go north" | |
redirect "/dais_room" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 3 is setting an instance variable, that is only available to instances of the class Input. Which it looks like you never make (Input.new). There are a couple of issues with this, primarily: if this worked, @input would not be accessible anywhere outside of the instance of Input, so line 10 would not work. Additionally, params[:input] is not going to work in that class because params in an instance method defined on whatever class Sinatra requests become, meaning it's only available in Sinatra's get/post/put/delete like methods.
That said, the concept here is good. I think you want to case params[:input] on lines 19 and 34. See https://gist.github.com/1510515 for a working example.