Showing posts with label form methods. Show all posts
Showing posts with label form methods. Show all posts

Wednesday, December 21, 2011

Working with the Method method in Ruby

So with the help of my friend Z (also known as Chris to some, mostly just his wife) I've made some progress on Dungeon Crawler. But not much.

Namely, he showed me how to abstract my routing, so rather than having

get "/torch_room" do
  @torch_room = torch_room
  erb :torch_room
end


I have a method that automatically builds a route based on methods that already exist for rooms. Pretty awesome! I think learning to be less specific and abstracting my code is one of the most difficult things I'm learning. One of the guiding tenets of Ruby is DRY (Don't Repeat Yourself) and I really just need to be aware when I'm writing the same basic code more than once that it can probably be abstracted.

Ok, but here's my problem. I still can't figure out a way to collect input from a form, pass that input into an instance variable so that I can check it from other rooms and perform redirects based on the input itself. Does that make sense? I am absolutely trying my hardest to be clear about what I'm trying to do. Z also clued me in on a Method method but I can't figure that out, either.

Here's a gist with what I've done so far, but (FAIR WARNING) it's straight up busted:

Busted Gist

That said, I've noticed a funny thing about this problem. Bear in mind I've been wrestling with this guy off and on since my last post. (I DID do a couple of fun tutorials in between wrestling matches, mostly to keep myself limbered up) I didn't get frustrated in the usual "FUCK IT I GIVE UP" kind of way, but more in a "huh that didn't work. Ok let's try another thing. Hmm nope, that didn't work either," kind of way.

I did try some CRAZY other things, based on what my friend Miles told me about last time I posted about this problem (said crazy things mostly involved working with hashes, trying to convert hashes to strings, etc. Does that work? PROBABLY, I DON'T KNOW!) with minimal success.

I think this is how Daniel-san felt when he realized the entire time he thought he was washing Mr. Miyagi's car, he was actually learning karate.

Tuesday, December 13, 2011

Trouble with Ruby form methods

I'm still working with my Dungeon Crawler Sinatra app. Believe it or not, I have a problem. I'm trying to get a simple form method working to allow a user to move from one room to another by typing in the direction he wants to move and then hitting 'Submit'. So good so far, right?

Here's a link to a gist of the code I've got so far:

Working with form methods

The second file I posted in the gist is code that works, but I'm looking for a cleaner way of manipulating the information collected from the form method. Does that make sense? This is probably easy enough to do, and @jqr gave me some help with it last week, but I can't figure out how to make these form methods behave.

On a side note, do you have a problem with getting distracted with new ideas for projects when you're in the middle of a project? This seems to happen to me all the time, and I've been handling it by saving as much as I can think of in a Google Doc. I wonder how other programmers handle this? Do you just write things down in a notebook? I've been thinking about creating a template to use for these project ideas, just to keep my thoughts a bit more organized. If any of you have a template like this, or suggestions on what would be key features, I'd love to hear them.

I actually think a simple drawing application that allows me to add notes and save to the cloud would be ideal, but I haven't heard of anything like this.